123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- 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\Factories\HasFactory;
- use Illuminate\Support\Facades\DB;
- 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;
-
- protected $guarded = [];
-
- protected $hidden = [
- 'password',
- ];
- protected static function booted()
- {
- }
-
- protected static function newFactory()
- {
- return UserFactory::new();
- }
-
- public function getJWTIdentifier()
- {
- return $this->getKey();
- }
-
- public function getJWTCustomClaims()
- {
- return ['role' => 'admin'];
- }
- public function getRolesNameAttribute()
- {
- return DB::table(config('permission.table_names.roles'))->select(['id', 'name', 'nickname'])->whereIn('id',
- DB::table(config('permission.table_names.model_has_roles'))->where('model_id', $this->attributes['id'])->pluck('role_id')
- )->get();
- }
- public function department()
- {
- return $this->belongsTo(Department::class)->select(['id', 'name'])->withDefault(['id' => 0, 'name' => '--']);
- }
- public function getHeadimgAttribute($val)
- {
- if (empty($val)) {
- return path_to_url('default/headImg.jpeg');
- }
- return path_to_url($val);
- }
-
- public static function byTypeIdGetId($type_id, $type)
- {
- return self::query()->where('type_id', $type_id)->where('type', $type)->value('id') ?? 0;
- }
- public static function byIdGetTypeId($id, $type)
- {
- return self::query()->where('id', $id)->where('type', $type)->value('type_id') ?? 0;
- }
-
- public function isSuperAdmin()
- {
- return in_array($this->attributes['id'], config('site.superAdmin_ids', []));
- }
- }
|