12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Models\BikeManage\Bike;
- use App\Repositories\Models\Model;
- 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 Laravel\Lumen\Auth\Authorizable;
- use Spatie\Permission\Traits\HasRoles;
- use Tymon\JWTAuth\Contracts\JWTSubject;
- class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
- {
- use Authenticatable, Authorizable, HasFactory, HasRoles;
- /**
- * @var string
- */
- protected $table = 'base_admins';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [
- 'password'
- ];
- protected $casts = [
- 'extra_fields' => 'json'
- ];
- /**
- * 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 ['role' => 'user'];
- }
- protected static function boot()
- {
- parent::boot(); // TODO: Change the autogenerated stub
- self::saved(function (User $model) {
- if ($model->type) {
- Admin::query()->find($model->id)->syncRoles($model->type);
- }
- });
- }
- public function department()
- {
- return $this->belongsTo(Department::class)->select(['id', 'name']);
- }
- public function bikes()
- {
- return $this->hasMany(Bike::class, 'user_id');
- }
- }
|