| Current Path : /var/www/html/redd/app/Models/Backend/ |
| Current File : /var/www/html/redd/app/Models/Backend/BackendUser.php |
<?php
namespace App\Models\Backend;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Attributes\Table;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Activitylog\Models\Activity;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;
use Spatie\Permission\Traits\HasRoles;
#[Table('backend_users')]
#[Fillable([
'username',
'email',
'email_verified_at',
'password',
'first_name',
'last_name',
'profile_picture',
'expires_at',
'two_factor_expires_at',
'two_factor_code',
'is_active',
'last_login_at',
])]
#[Hidden([
'password',
'two_factor_code',
'remember_token',
])]
class BackendUser extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable, LogsActivity, HasRoles;
protected string $guard_name = 'admin';
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'expires_at' => 'datetime',
'two_factor_expires_at' => 'datetime',
'is_active' => 'boolean',
'last_login_at' => 'datetime',
];
}
// override per-model sendemail
public function sendPasswordResetNotification($token)
{
ResetPassword::createUrlUsing(function ($notifiable, $token) {
return route('admin.password.reset', [
'token' => $token,
'email' => $notifiable->email,
]);
});
$this->notify(new ResetPassword($token));
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly(['username', 'email', 'first_name', 'last_name', 'profile_picture', 'is_active']) //utk log hanya username dan email
// ->logFillable() // utk log semua field fillable
->useLogName('Backend User') // utk log name
->setDescriptionForEvent(fn(string $eventName) => "This model has been {$eventName}") // utk log description
->dontLogEmptyChanges();
}
}