// Get the user
$user = \App\Models\User::where('email', 'admin@admin.com')->first();
// Assign admin role
$user->assignRole('admin');
// Verify the role was assigned
$user->hasRole('admin'); // Should now return true
// Check permissions
$user->getAllPermissions()->pluck('name'); // Should show all admin permissions
or
**
app/Console/Commands/AssignAdminRole.php
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class AssignAdminRole extends Command
{
protected $signature = 'role:assign-admin {email}';
protected $description = 'Assign admin role to a user';
public function handle()
{
$user = User::where('email', $this->argument('email'))->first();
if ($user) {
$user->assignRole('admin');
$this->info('Admin role assigned successfully.');
} else {
$this->error('User not found.');
}
}
}
php artisan role:assign-admin newadmin@example.com
**