%PDF- %PDF-
Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Models/ |
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Models/User.php |
<?php namespace App\Models; use Illuminate\Support\Str; use Laravel\Cashier\Billable; use Illuminate\Support\Facades\Storage; use Spatie\Permission\Traits\HasRoles; use Tymon\JWTAuth\Contracts\JWTSubject; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable implements MustVerifyEmail, JWTSubject { use HasFactory, Notifiable, Billable, HasRoles; protected $guard_name = 'api'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'business_type', 'stripe_connect_id', 'photo_url', 'first_name', 'last_name', 'email', 'phone', 'password', 'trial_ends_at' ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', 'trial_ends_at' => 'datetime:Y-m-d', 'communication_settings' => 'array' ]; /** * The accessors to append to the model's array form. * * @var array */ protected $appends = [ 'photo', 'full_name', 'location' ]; /** * Send the password reset notification. * * @param string $token * @return void */ public function sendPasswordResetNotification($token) { $this->notify(new \App\Notifications\ResetPasswordNotification($token)); } /** * 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 []; } /** * Route notifications for the Nexmo channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForNexmo($notification) { return $this->phone; } /** * Get the photo * * @return string */ public function getPhotoAttribute() { $isExternal = Str::contains($this->photo_url, ['http', 'https']); return $isExternal ? $this->photo_url : url(Storage::url($this->photo_url)); } /** * Get the user's full name. * * @return string */ public function getFullNameAttribute() { return "{$this->first_name} {$this->last_name}"; } /** * Get the user's full name. * * @return string */ public function getLocationAttribute() { $defaultLocation = $this->addresses->where('is_default')->first(); if($defaultLocation == null) { return $this->addresses->first(); } return $defaultLocation; } /** * Get the therapist profile associated with the user. */ public function therapist() { return $this->hasOne(Therapist::class); } /** * Get the products for the user. */ public function products() { return $this->hasMany(Product::class) ->orderBy('price', 'asc') ->where('price', '!=', 0); } /** * Get users blog posts */ public function posts() { return $this->hasMany(Post::class); } /** * Get the user's addresses */ public function addresses() { return $this->hasMany(UserAddress::class); } /** * Get the user's bookings */ public function bookings() { return $this->hasMany(Booking::class); } /** * Get the user's messages */ public function messages() { return $this->hasMany(Message::class); } }