| Current Path : /var/www/html/dynaweb-cms-v1/app/Models/Backend/ |
| Current File : /var/www/html/dynaweb-cms-v1/app/Models/Backend/FrontendUser.php |
<?php
namespace App\Models\Backend;
use App\Http\Helpers\SettingHelper;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Attributes\Table;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Support\Facades\URL;
use Spatie\Activitylog\Models\Activity;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;
use Spatie\Permission\Traits\HasRoles;
#[Table('frontend_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 FrontendUser extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable, LogsActivity, HasRoles;
protected $guard_name = 'user';
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',
];
}
public function sendPasswordResetNotification($token)
{
$slug = SettingHelper::defaultSiteSlug();
ResetPassword::createUrlUsing(function ($notifiable, $token) use ($slug) {
return url('/' . $slug . '/reset-password-web?token=' . $token . '&email=' . urlencode($notifiable->email));
});
$this->notify(new ResetPassword($token));
}
public function sendEmailVerificationNotification()
{
VerifyEmail::createUrlUsing(function ($notifiable) {
return url('/user/email/verify/' . $notifiable->getKey() . '/' . sha1($notifiable->getEmailForVerification()));
});
$this->notify(new VerifyEmail());
}
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();
}
}