*/ use HasFactory, Notifiable, HasApiTokens, SoftDeletes; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', 'firstname', 'lastname', 'position' ]; protected $dates = ['deleted_at']; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } public function delete(){ $this->email = $this->email . '_deleted_'. now()->timestamp; $this->save(); return parent::delete(); } public function roles(){ return $this->belongsToMany(Role::class, 'user_role')->withTimestamps(); } public function menus(){ return Menu::whereHas('roles', function ($query){ $query->whereIn('roles.id', $this->roles->pluck('id')) ->where('role_menu.allow_show', true); }); } }