You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

94 lines
2.0 KiB

<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
// soft delete
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array<int, string>
*/
protected $dates = ['deleted_at'];
protected $guard = [];
protected $guard_name = '*';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'api_token',
'account',
'status',
'class',
'leader',
'exp_op',
'unit',
'device',
'deleted_at',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
'api_token'
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
// append attribute
protected $appends = ['role_name','station'];
public function userLog()
{
return $this->hasMany(UserLog::class);
}
// get role name attribute
public function getRoleNameAttribute()
{
return $this->roles->pluck('display_name')->first();
}
// get station attribute
public function getStationAttribute()
{
return '交通警察大隊';
}
// get status attribute
// public function getStatusAttribute($value)
// {
// return $value == 0 ? '啟用' : '停用';
// }
}