Benutzerrollen (Administrator, Vermietung, Inhalte) und Benutzerverwaltung
- Rollenbasierte Policies, Navigationsgruppen - Media Library (Spatie) für die kommende Bildverwaltung installiert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
08b6582fa1
commit
27ea12901e
25 files changed
+1341
-81
No files matched your search
+10
-3
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Enums\UserRole;
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
@@ -12,7 +13,7 @@
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Fillable(['name', 'email', 'role', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
@@ -20,11 +21,16 @@ class User extends Authenticatable implements FilamentUser
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* Only administrators have accounts; there is no public registration.
|
||||
* Accounts are created by administrators only; an account without a role has no access.
|
||||
*/
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return true;
|
||||
return $this->role !== null;
|
||||
}
|
||||
|
||||
public function hasRole(UserRole ...$roles): bool
|
||||
{
|
||||
return in_array($this->role, $roles, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,6 +43,7 @@ protected function casts(): array
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'role' => UserRole::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user