91 lines
2.0 KiB
PHP
91 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
/**
|
|
* @mixin IdeHelperUser
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
use LogsActivity, HasFactory, Notifiable;
|
|
|
|
/**
|
|
* The model's default values for attributes.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $attributes = [
|
|
'is_admin' => false,
|
|
'status' => true,
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'firstname',
|
|
'lastname',
|
|
'email',
|
|
'uuid',
|
|
'profile',
|
|
'status',
|
|
'is_admin',
|
|
'password',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'is_admin' => 'boolean',
|
|
'status' => 'boolean',
|
|
'password' => 'hashed',
|
|
];
|
|
|
|
public function getFullNameAttribute(): string
|
|
{
|
|
return "$this->firstname $this->lastname";
|
|
}
|
|
|
|
public function tapActivity(Activity $activity, string $eventName)
|
|
{
|
|
switch ($eventName) {
|
|
case 'created':
|
|
$activity->description = "User created: {$this->full_name}";
|
|
return;
|
|
case 'deleted':
|
|
$activity->description = "User deleted: {$this->full_name}";
|
|
return;
|
|
default;
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function getActivityLogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logExcept(['password']);
|
|
}
|
|
}
|