123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Models;
- // use Illuminate\Contracts\Authenticate\MustVerifyEmail;
- use DateTimeInterface;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- use Laravel\Sanctum\HasApiTokens;
- use Tymon\JWTAuth\Contracts\JWTSubject;
- class Admin extends Authenticatable implements JWTSubject
- {
- use HasApiTokens, HasFactory, Notifiable;
- // use SoftDeletes;
- // 设置表名
- protected $table = 'admin';
- // 设置主键
- // public $primaryKey = 'id';
- /**
- * 自动生成时间戳
- */
- // public $timestamps = FALSE;
- // const CREATED_AT = 'create_time';
- // const UPDATED_AT = 'update_time';
- // 自定义软删除字段 默认 deleted_at
- // const DELETED_AT = 'delete_at';
- /**
- * 日期时间的存储格式
- *
- * @var string
- */
- // protected $dateFormat = 'Y-m-d H:i:s';
- /**
- * The attributes that are mass assignable.
- *
- * @var array<int, string>
- */
- protected $fillable = [];
- /**
- * 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 = [
- 'create_at' => 'datetime', //'datetime:Y-m-d H:i:s'
- 'password' => 'hashed',
- ];
- protected $appends = ['roles'];
- public function getRolesAttribute()
- {
- return AdminRole::where(['admin_id' => $this->id])->pluck('id');
- }
- protected function serializeDate(DateTimeInterface $date): string
- {
- return $date->format('Y-m-d H:i:s');
- }
- /**
- * @inheritDoc
- */
- public function getJWTIdentifier()
- {
- return $this->getKey();
- }
- /**
- * @inheritDoc
- */
- public function getJWTCustomClaims(): array
- {
- return [];
- }
- }
|