diff --git a/app/Permissions/UsersPermissions.php b/app/Permissions/UsersPermissions.php index 7291619e..e079011d 100644 --- a/app/Permissions/UsersPermissions.php +++ b/app/Permissions/UsersPermissions.php @@ -10,20 +10,20 @@ class UsersPermissions { /** Permission for listing and view all users. */ - public const CAN_LIST_USERS = 'list-users'; + public const CAN_LIST_USERS = 'users.list'; /** Permission for showing users itself. */ - public const CAN_SHOW_USERS = 'show-users'; + public const CAN_SHOW_USERS = 'users.show'; /** Permission for creating users. */ - public const CAN_CREATE_USERS = 'create-users'; + public const CAN_CREATE_USERS = 'users.create'; /** Permission for updating users. */ - public const CAN_UPDATE_USERS = 'update-users'; + public const CAN_UPDATE_USERS = 'users.update'; /** Permission for updating users itself. */ - public const CAN_UPDATE_USERS_SELF = 'update-users-self'; + public const CAN_UPDATE_USERS_SELF = 'users.update.self'; /** Permission for deleting users. */ - public const CAN_DELETE_USERS = 'delete-users'; + public const CAN_DELETE_USERS = 'users.delete'; } diff --git a/database/migrations/2023_12_13_214743_add_user_permissions.php b/database/migrations/2023_12_13_214743_add_user_permissions.php index fb6336fd..0eb540d4 100644 --- a/database/migrations/2023_12_13_214743_add_user_permissions.php +++ b/database/migrations/2023_12_13_214743_add_user_permissions.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; +use Spatie\Permission\Models\Permission; return new class extends Migration { @@ -12,46 +13,30 @@ */ public function up(): void { - DB::table('permissions')->insert( - [ - [ - 'name' => UsersPermissions::CAN_LIST_USERS, - 'guard_name' => 'web', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'name' => UsersPermissions::CAN_SHOW_USERS, - 'guard_name' => 'web', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'name' => UsersPermissions::CAN_CREATE_USERS, - 'guard_name' => 'web', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'name' => UsersPermissions::CAN_UPDATE_USERS, - 'guard_name' => 'web', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'name' => UsersPermissions::CAN_UPDATE_USERS_SELF, - 'guard_name' => 'web', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ], - [ - 'name' => UsersPermissions::CAN_DELETE_USERS, - 'guard_name' => 'web', - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ] - ] - ); + Permission::create([ + 'name' => 'users.list', + 'guard_name' => 'web', + ]); + Permission::create([ + 'name' => 'users.show', + 'guard_name' => 'web', + ]); + Permission::create([ + 'name' => 'users.create', + 'guard_name' => 'web', + ]); + Permission::create([ + 'name' => 'users.update', + 'guard_name' => 'web', + ]); + Permission::create([ + 'name' => 'users.update.self', + 'guard_name' => 'web', + ]); + Permission::create([ + 'name' => 'users.delete', + 'guard_name' => 'web', + ]); } /** @@ -60,12 +45,12 @@ public function up(): void public function down(): void { DB::table('permissions')->whereIn('name', [ - UsersPermissions::CAN_LIST_USERS, - UsersPermissions::CAN_SHOW_USERS, - UsersPermissions::CAN_CREATE_USERS, - UsersPermissions::CAN_UPDATE_USERS, - UsersPermissions::CAN_UPDATE_USERS_SELF, - UsersPermissions::CAN_DELETE_USERS, + 'users.list', + 'users.show', + 'users.create', + 'users.update', + 'users.update.self', + 'users.delete', ])->delete(); } };