- Added `RestrictedUserPermission` migration and model for managing user-role-permission restrictions. - Introduced `UserService`, `RoleService`, and related DTOs for handling user access, role assignments, and permission restrictions. - Created new Livewire components and Blade views for user management, including role/permission assignment modals. - Updated navigation and routing to include the "Users" section under "Access Manager." - Enhanced `RoleService` with methods for retrieving permissions and managing role-user interactions. - Improved UI with permission toggles and streamlined selection features for better user-role management.
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\{Fillable, Hidden};
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Str;
|
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
#[Fillable(['name', 'email', 'password'])]
|
|
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
|
|
final class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, SoftDeletes;
|
|
|
|
use HasRoles;
|
|
use Notifiable;
|
|
use TwoFactorAuthenticatable;
|
|
|
|
public function restrictedPermissions(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
\Spatie\Permission\Models\Permission::class,
|
|
'restricted_user_permissions',
|
|
'user_id',
|
|
'permission_id'
|
|
)->withPivot('role_id')->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* Get the user's initials
|
|
*/
|
|
public function initials(): string
|
|
{
|
|
return Str::of($this->name)
|
|
->explode(' ')
|
|
->take(2)
|
|
->map(fn ($word) => Str::substr($word, 0, 1))
|
|
->implode('');
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
}
|
|
}
|