-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use Illuminate\Database\Console\Seeds\WithoutModelEvents; | ||
use Illuminate\Database\Seeder; | ||
use Spatie\Permission\Models\Permission; | ||
use Spatie\Permission\Models\Role; | ||
use Spatie\Permission\PermissionRegistrar; | ||
|
||
class PermissionSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() | ||
{ | ||
// Reset cached roles and permissions | ||
app()[PermissionRegistrar::class]->forgetCachedPermissions(); | ||
|
||
// create permissions | ||
Permission::create(['name' => 'create clients']); | ||
Permission::create(['name' => 'edit clients']); | ||
Permission::create(['name' => 'delete clients']); | ||
|
||
Permission::create(['name' => 'create contacts']); | ||
Permission::create(['name' => 'edit contacts']); | ||
Permission::create(['name' => 'delete contacts']); | ||
|
||
Permission::create(['name' => 'manage users']); | ||
|
||
|
||
|
||
// create roles and assign existing permissions | ||
$role1 = Role::create(['name' => 'comper']); | ||
$role1->givePermissionTo('create clients'); | ||
$role1->givePermissionTo('edit clients'); | ||
$role1->givePermissionTo('create contacts'); | ||
$role1->givePermissionTo('edit contacts'); | ||
|
||
$role2 = Role::create(['name' => 'volunteer']); | ||
$role2->givePermissionTo('create clients'); | ||
$role2->givePermissionTo('edit clients'); | ||
$role2->givePermissionTo('delete clients'); | ||
$role2->givePermissionTo('create contacts'); | ||
$role2->givePermissionTo('edit contacts'); | ||
$role2->givePermissionTo('delect contacts'); | ||
|
||
$role3 = Role::create(['name' => 'director']); | ||
$role3->givePermissionTo('create clients'); | ||
$role3->givePermissionTo('edit clients'); | ||
$role3->givePermissionTo('delete clients'); | ||
$role3->givePermissionTo('create contacts'); | ||
$role3->givePermissionTo('edit contacts'); | ||
$role3->givePermissionTo('delete contacts'); | ||
$role3->givePermissionTo('manage users'); | ||
|
||
$role4 = Role::create(['name' => 'Super-Admin']); | ||
// gets all permissions via Gate::before rule; see AuthServiceProvider | ||
|
||
// create demo users | ||
$user = \App\Models\User::factory()->create([ | ||
'name' => 'Example User', | ||
'email' => '[email protected]', | ||
]); | ||
$user->assignRole($role1); | ||
|
||
$user = \App\Models\User::factory()->create([ | ||
'name' => 'Example Admin User', | ||
'email' => '[email protected]', | ||
]); | ||
$user->assignRole($role2); | ||
|
||
$user = \App\Models\User::factory()->create([ | ||
'name' => 'Example Super-Admin User', | ||
'email' => '[email protected]', | ||
]); | ||
$user->assignRole($role3); | ||
} | ||
} |