22
33namespace Database \Seeders ;
44
5+ use App \Enums \Permission ;
6+ use App \Enums \Role ;
57use Illuminate \Database \Console \Seeds \WithoutModelEvents ;
68use Illuminate \Database \Seeder ;
79use Illuminate \Support \Collection ;
8- use Spatie \Permission \Models \Permission ;
9- use Spatie \Permission \Models \Role ;
10+ use Spatie \Permission \Models \Permission as SpatiePermission ;
11+ use Spatie \Permission \Models \Role as SpatieRole ;
1012
1113class RolesAndPermissionsSeeder extends Seeder
1214{
@@ -28,31 +30,32 @@ public function run()
2830 protected function createRoles ()
2931 {
3032 $ this ->roles = \collect ([
31- ' admin ' => Role ::create (['name ' => ' admin ' ]),
32- ' user ' => Role ::create (['name ' => ' user ' ]),
33+ Role:: ADMIN -> value => SpatieRole ::create (['name ' => Role:: ADMIN ]),
34+ Role:: USER -> value => SpatieRole ::create (['name ' => Role:: USER ]),
3335 ]);
3436 }
3537
3638 protected function createPermissions ()
3739 {
3840 $ this ->orgnaisationPermissions = \collect ([
39- Permission::create (['name ' => 'manage-organisation ' ]),
41+ SpatiePermission::create (['name ' => Permission::EDIT_ORGANISATION ]),
42+ SpatiePermission::create (['name ' => Permission::UPDATE_ORGANISATION ]),
4043 ]);
4144
4245 $ this ->postPermissions = \collect ([
43- Permission ::create (['name ' => ' create-posts ' ]),
44- Permission ::create (['name ' => ' view-posts ' ]),
45- Permission ::create (['name ' => ' edit-posts ' ]),
46- Permission ::create (['name ' => ' update-posts ' ]),
47- Permission ::create (['name ' => ' delete-posts ' ]),
46+ SpatiePermission ::create (['name ' => Permission:: CREATE_POSTS ]),
47+ SpatiePermission ::create (['name ' => Permission:: VIEW_POSTS ]),
48+ SpatiePermission ::create (['name ' => Permission:: EDIT_POSTS ]),
49+ SpatiePermission ::create (['name ' => Permission:: UPDATE_POSTS ]),
50+ SpatiePermission ::create (['name ' => Permission:: DELETE_POSTS ]),
4851 ]);
4952 }
5053
5154 protected function assignPermissionsToRoles ()
5255 {
53- $ this ->roles ->get (' admin ' )->givePermissionTo ($ this ->postPermissions );
54- $ this ->roles ->get (' admin ' )->givePermissionTo ($ this ->orgnaisationPermissions );
56+ $ this ->roles ->get (Role:: ADMIN -> value )->givePermissionTo ($ this ->postPermissions );
57+ $ this ->roles ->get (Role:: ADMIN -> value )->givePermissionTo ($ this ->orgnaisationPermissions );
5558
56- $ this ->roles ->get (' user ' )->givePermissionTo ($ this ->postPermissions );
59+ $ this ->roles ->get (Role:: USER -> value )->givePermissionTo ($ this ->postPermissions );
5760 }
5861}
0 commit comments