- Created media-library configuration file for managing media uploads and conversions. - Added permission configuration file to define roles and permissions. - Implemented migration for media table to store media items with necessary attributes. - Created migration for permission tables to manage roles and permissions relationships. - Updated DatabaseSeeder to include RolePermissionSeeder for seeding roles and permissions. - Added RolePermissionSeeder to define specific permissions and roles for the application. - Modified UserSeeder to assign roles to users during seeding.
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
#[Hidden(['password'])]
|
|
#[Guarded(['id', 'last_login_at'])]
|
|
#[Appends(['full_name'])]
|
|
class User extends Authenticatable
|
|
{
|
|
use HasFactory, HasRoles, Notifiable, SoftDeletes;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_active' => 'boolean',
|
|
'last_login_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'two_factor_confirmed_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
protected function fullName(): Attribute
|
|
{
|
|
return Attribute::get(function () {
|
|
return $this->profile?->full_name ?? $this->username;
|
|
});
|
|
}
|
|
|
|
public function profile(): HasOne
|
|
{
|
|
return $this->hasOne(UserProfile::class);
|
|
}
|
|
}
|