Skip to content

Commit

Permalink
refactor(role): update naming and creation process (#106)
Browse files Browse the repository at this point in the history
Improve codebase clarity by adopting dot notation for role permissions'
naming and utilizing the models create function for permission creation.

---------

Signed-off-by: Valentin Sickert <[email protected]>
  • Loading branch information
Lapotor authored Jan 9, 2024
1 parent 624b62e commit edbdc6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
8 changes: 4 additions & 4 deletions app/Permissions/RolesPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
class RolesPermissions
{
/** Permission for showing roles. */
public const CAN_SHOW_ROLES = 'show-roles';
public const CAN_SHOW_ROLES = 'roles.show';

/** Permission for creating users. */
public const CAN_CREATE_ROLES = 'create-roles';
public const CAN_CREATE_ROLES = 'roles.create';

/** Permission for updating users. */
public const CAN_UPDATE_ROLES = 'update-roles';
public const CAN_UPDATE_ROLES = 'roles.update';

/** Permission for deleting users. */
public const CAN_DELETE_ROLES = 'delete-roles';
public const CAN_DELETE_ROLES = 'roles.delete';
}
49 changes: 20 additions & 29 deletions database/migrations/2023_12_14_193625_add_roles_permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Permissions\RolesPermissions;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Spatie\Permission\Models\Permission;

return new class extends Migration
{
Expand All @@ -11,31 +12,21 @@
*/
public function up(): void
{
DB::table('permissions')->insert([
[
'name' => RolesPermissions::CAN_SHOW_ROLES,
'guard_name' => 'web',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => RolesPermissions::CAN_CREATE_ROLES,
'guard_name' => 'web',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => RolesPermissions::CAN_UPDATE_ROLES,
'guard_name' => 'web',
'created_at' => now(),
'updated_at' => now(),
],
[
'name' => RolesPermissions::CAN_DELETE_ROLES,
'guard_name' => 'web',
'created_at' => now(),
'updated_at' => now(),
],
Permission::create([
'name' => 'roles.show',
'guard_name' => 'web',
]);
Permission::create([
'name' => 'roles.create',
'guard_name' => 'web',
]);
Permission::create([
'name' => 'roles.update',
'guard_name' => 'web',
]);
Permission::create([
'name' => 'roles.delete',
'guard_name' => 'web',
]);
}

Expand All @@ -45,10 +36,10 @@ public function up(): void
public function down(): void
{
DB::table('permissions')->whereIn('name', [
RolesPermissions::CAN_SHOW_ROLES,
RolesPermissions::CAN_CREATE_ROLES,
RolesPermissions::CAN_UPDATE_ROLES,
RolesPermissions::CAN_DELETE_ROLES,
'roles.show',
'roles.create',
'roles.update',
'roles.delete',
])->delete();
}
};

0 comments on commit edbdc6d

Please sign in to comment.