How can I assign roles in the Seeder

611 views Asked by At
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)?

1

There are 1 answers

0
Joukhar On

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 ! ༼ つ ◕_◕ ༽つ