Home > front end >  How can I assign roles in the Seeder
How can I assign roles in the Seeder

Time:06-08

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {

        $this->call(LaratrustSeeder::class);
    }
}

How can I assign roles for the users that will be created by the seeder (with Laratrust)?

CodePudding user response:

You can create user seeder by this command php artisan make:seeder UserSeeder

if you already have it Follow this :

User::create([
        'name' => 'Mouise Bashir',
        'country'=>'undefined',
        'email' => '[email protected]',
        'email_verified_at' => now(),
        'password' => Hash::make('Bashir123'),
        'remember_token' => Str::random(60),
    ])->assignRole('admin'); // here add your role 

i hope it was useful ! ༼ つ ◕_◕ ༽つ

CodePudding user response:

$user->attachRole('admin');

  • Related