You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xshop/database/seeders/UserSeeder.php

62 lines
1.4 KiB
PHTML

8 months ago
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
8 months ago
use Spatie\Permission\Models\Role;
8 months ago
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// developer
User::factory()->create(
[
'name' => 'WebDeveloper',
'email' => 'developer@example.com',
'role'=> 'DEVELOPER',
]
);
// website admin
User::factory()->create(
[
'name' => 'Admin',
'email' => 'admin@example.com',
'role'=> 'ADMIN',
]
);
// website user
User::factory()->create(
[
'name' => 'ManagerUser',
'email' => 'user@example.com',
]
);
8 months ago
// add roles
foreach (User::$roles as $role) {
$r = new Role();
$r->name = strtolower($role);
$r->save();
}
$developer = User::whereId(1)->first();
$developer->assignRole('developer');
$developer->save();
$admin = User::whereId(2)->first();
$admin->assignRole('admin');
$admin->save();
$user = User::whereId(3)->first();
$user->assignRole('user');
$user->save();
8 months ago
}
}