Integrate Spatie Laravel Permission to replace the legacy role system. This includes: - Adding `spatie/laravel-permission` dependency. - Implementing `Role` and `User` model updates with `HasRoles` trait. - Adding migrations for permission and role tables. - Creating `RoleResource` and `UserResource` for Filament administration. - Adding a `RoleAndPermissionSeeder` for initial setup. - Updating `User` model helper methods to utilize role checks.
22 lines
602 B
PHP
22 lines
602 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Spatie\Permission\Models\Role as SpatieRole;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class Role extends SpatieRole
|
|
{
|
|
/**
|
|
* رابطه با کاربران دارای این نقش
|
|
*/
|
|
public function users(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
config('auth.providers.users.model', 'App\\Models\\User'),
|
|
config('permission.table_names.model_has_roles', 'model_has_roles'),
|
|
'role_id',
|
|
config('permission.column_names.model_morph_key', 'model_id')
|
|
);
|
|
}
|
|
} |