feat: add spatie/laravel-permission & its implementation at panel
This commit is contained in:
@@ -8,11 +8,12 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable, TwoFactorAuthenticatable, MustVerifyEmail;
|
||||
use HasFactory, Notifiable, TwoFactorAuthenticatable, MustVerifyEmail, HasRoles;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -23,6 +24,7 @@ class User extends Authenticatable
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'email_verified_at',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use Auth;
|
||||
use Backstage\FilamentMails\Facades\FilamentMails;
|
||||
use Backstage\FilamentMails\FilamentMailsPlugin;
|
||||
use Boquizo\FilamentLogViewer\FilamentLogViewerPlugin;
|
||||
@@ -62,7 +63,22 @@ class DashPanelProvider extends PanelProvider
|
||||
->plugins([
|
||||
FilamentLoggerPlugin::make(),
|
||||
FilamentLogViewerPlugin::make(),
|
||||
FilamentMailsPlugin::make(),
|
||||
FilamentMailsPlugin::make()->canManageMails(function () {
|
||||
$user = Auth::user();
|
||||
|
||||
// Allow access for users with specific roles
|
||||
if ($user->hasRole('admin')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow access for users with specific permissions
|
||||
if ($user->hasPermissionTo('manage mails')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Restrict access for all other users
|
||||
return false;
|
||||
}),
|
||||
])
|
||||
->routes(fn () => FilamentMails::routes());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user