Thirdwrist

Untitled

Apr 7th, 2021
380
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class User extends Authenticatable implements JWTSubject
  2. {
  3.     use HasFactory, Notifiable, HasPermissions, HasRoles;
  4.  
  5.     /**
  6.      * The attributes that should be cast to native types.
  7.      *
  8.      * @var array
  9.      */
  10.     protected $guarded = [];
  11.    
  12.     protected $hidden = [
  13.         'password',
  14.         'remember_token',
  15.     ];
  16.  
  17.     protected $casts = [
  18.         'email_verified_at' => 'datetime',
  19.         'date_of_birth'=>'datetime:Y-m-d'
  20.     ];
  21.  
  22.     protected $guard_name = 'api';
  23.  
  24.     protected $with = [
  25.         'driver',
  26.         'rider',
  27.     ];
  28.  
  29.     /**
  30.      * Get the identifier that will be stored in the subject claim of the JWT.
  31.      *
  32.      * @return mixed
  33.      */
  34.     public function getJWTIdentifier()
  35.     {
  36.         return $this->getKey();
  37.     }
  38.  
  39.     /**
  40.      * Return a key value array, containing any custom claims to be added to the JWT.
  41.      *
  42.      * @return array
  43.      */
  44.     public function getJWTCustomClaims()
  45.     {
  46.         return [];
  47.     }
  48.  
  49.  
  50.     public function role()
  51.     {
  52.         if($this->hasRole(RoleEnum::RIDER) && !$this->hasRole(RoleEnum::DRIVER))
  53.         {
  54.             return $this->hasOne(Rider::class);
  55.         }
  56.  
  57.         if($this->hasRole(RoleEnum::DRIVER) && !$this->hasRole(RoleEnum::RIDER))
  58.         {
  59.             return $this->hasOne(Driver::class);
  60.         }
  61.     }
  62.  
  63.     public function driver()
  64.     {
  65.         return $this->hasOne(Driver::class);
  66.     }
  67.  
  68.     public function rider()
  69.     {
  70.         return $this->hasOne(Rider::class);
  71.     }
  72. }
  73.  
  74.  
  75. class Driver extends Model
  76. {
  77.     use HasFactory;
  78.  
  79.     protected $with = ['user'];
  80.  
  81.     protected $guarded = [];
  82.  
  83.     public function user()
  84.     {
  85.         return $this->belongsTo(User::class);
  86.     }
  87.  
  88.     public function rideRequestMatches(){
  89.         return $this->hasMany(RideRequestMatch::class);
  90.     }
  91.  
  92.     public function cars(){
  93.         return $this->hasMany(Car::class);
  94.     }
  95.  
  96.     public function rideRequests(){
  97.         return $this->hasMany(RideRequest::class);
  98.     }
  99.  
  100. }
  101.  
  102.  
  103. class Rider extends Model
  104. {
  105.     use HasFactory;
  106.  
  107.     protected $guarded = [];
  108.     protected $with = ['user'];
  109.  
  110.     public function user()
  111.     {
  112.         return $this->belongsTo(User::class);
  113.     }
  114.  
  115.     public function paymentCards()
  116.     {
  117.         return $this->hasMany(PaymentCard::class);
  118.     }
  119. }
  120.  
  121.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×