add Spatie\Permission roles, seeder and changes README.md
This commit is contained in:
@ -6,6 +6,9 @@ use App\Models\User;
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
@ -15,9 +18,25 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
// Create roles
|
||||
$adminRole = Role::create(['name' => 'admin']);
|
||||
$privilegedRole = Role::create(['name' => 'privileged']);
|
||||
|
||||
// Create permissions
|
||||
$editPermission = Permission::create(['name' => 'edit articles']);
|
||||
$deletePermission = Permission::create(['name' => 'delete articles']);
|
||||
|
||||
// Assign permissions to roles
|
||||
$adminRole->givePermissionTo([$editPermission, $deletePermission]);
|
||||
$privilegedRole->givePermissionTo($editPermission);
|
||||
|
||||
User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'password' => '12341234'
|
||||
]);
|
||||
|
||||
$user = User::find(1); // get a user
|
||||
$user->assignRole('admin');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user