123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Repositories\Models\Base;
- use App\Repositories\Models\Model;
- use Database\Factories\UserFactory;
- use Illuminate\Auth\Authenticatable;
- use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
- use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Support\Facades\App;
- use Illuminate\Support\Facades\Hash;
- use Laravel\Lumen\Auth\Authorizable;
- use Spatie\Permission\Traits\HasRoles;
- use Tymon\JWTAuth\Contracts\JWTSubject;
- class Admin extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
- {
- protected $table = 'base_admins';
- use Authenticatable, Authorizable, HasFactory, HasRoles;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- // protected $fillable = [
- // 'name', 'avatar', 'username'
- // ];
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [
- 'password',
- ];
- protected static function booted()
- {
- self::language();
- }
- /**
- * 兼容 Laravel 8 的 Factory.
- *
- * @return UserFactory
- */
- protected static function newFactory()
- {
- return UserFactory::new();
- }
- /**
- * Get the identifier that will be stored in the subject claim of the JWT.
- *
- * @return mixed
- */
- public function getJWTIdentifier()
- {
- return $this->getKey();
- }
- /**
- * Return a key value array, containing any custom claims to be added to the JWT.
- *
- * @return array
- */
- public function getJWTCustomClaims()
- {
- // return ['admin'];
- return ['role' => 'admin'];
- }
- public function role()
- {
- return $this->belongsTo(Role::class);
- }
- public function department()
- {
- return $this->belongsTo(Department::class);
- }
- public function getHeadimgAttribute($val)
- {
- if (is_null($val)) {
- return path_to_url('default/headImg.jpeg');
- }
- return path_to_url($val);
- }
- }
|