%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Models/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Models/Therapist.php

<?php

namespace App\Models;

use Carbon\Carbon;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Therapist extends Model
{
    use HasFactory, HasSlug;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'user_id',
        'slug',
        'description',
        'specialism_id',
        'gender',
        'colour',
        'image_url_one',
        'image_two_url',
        'is_complete',
        'is_authorised'
    ];

    /**
     * Get the options for generating the slug.
     */
    public function getSlugOptions() : SlugOptions
    {
        return SlugOptions::create()
            ->generateSlugsFrom(function (\App\Models\Therapist $therapist) {
                return $therapist->user->first_name.'-'.$therapist->user->last_name;
            })->saveSlugsTo('slug');
    }

    /**
     * Scope a query to only include active therapists.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeActive($query)
    {
        return $query->where('is_complete', 1)
            ->where('is_authorised', 1)
            ->whereHas('user', function (Builder $query) {
                $query->whereHas('subscriptions', function($query) {
                    $query->where('stripe_status', 'trialing')
                        ->orWhere('stripe_status', 'active');
                });
            });
    }

    /**
     * Scope a query to only include active therapists.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $query
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeBookingEnabled($query)
    {
        return $query->has('user.products')
            ->has('sessions')
            ->whereHas('user', function (Builder $query) {
                $query->whereNotNull('stripe_connect_id');
            });
    }

    /**
     * Get the user.
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Get the therapist bookings
     */
    public function bookings()
    {
        return $this->hasMany(Booking::class);
    }

    /**
     * Get the therapists availability
     */
    public function availability()
    {
        return $this->hasMany(Availability::class);
    }

    /**
     * Get the therapists clients
     */
    public function clients()
    {
        return $this->belongsToMany(User::class, 'clients', 'therapist_id', 'user_id')
            ->withPivot('therapist_id')
            ->using(Client::class)
            ->withTimestamps();
    }

    /**
     * Get the therapists tags
     */
    public function tags()
    {
        return $this->belongsToMany(Tag::class, 'therapist_tags', 'therapist_id', 'tag_id');
    }

    /**
     * Get the session types available for this therapist.
     */
    public function sessions()
    {
        return $this->belongsToMany(Session::class);
    }

    /**
     * Get the languages for this therapist
     */
    public function languages()
    {
        return $this->belongsToMany(Language::class);
    }

    /**
     * Get the specialisms available for this therapist.
     */
    public function specialisms()
    {
        return $this->belongsToMany(Specialism::class)
            ->withPivot(['is_main'])
            ->wherePivot('is_main', 0);
    }

    /**
     * Get the main specialism for this therapist.
     */
    public function main_specialism()
    {
        return $this->belongsTo(Specialism::class, 'specialism_id', 'id');
    }

    /**
     * Get the first set of therapist questions
     */
    public function questions_one()
    {
        return $this->hasMany(TherapistQuestion::class)
            ->whereHas('parent', function (Builder $query) {
                $query->where('section_id', 1);
            });
    }

    /**
     * Get the second set of therapist questions
     */
    public function questions_two()
    {
        return $this->hasMany(TherapistQuestion::class)
            ->whereHas('parent', function (Builder $query) {
                $query->where('section_id', 2);
            });
    }

    /**
     * Get the therapist qualifications
     */
    public function qualifications()
    {
        return $this->hasMany(Qualification::class);
    }

    /**
     * Get the therapist memberships
     */
    public function memberships()
    {
        return $this->hasMany(Membership::class);
    }

    /**
     * Get the therapist insurance
     */
    public function insurance()
    {
        return $this->hasOne(Insurance::class);
    }

    /**
     * Get the therapist supervisor
     */
    public function supervisor()
    {
        return $this->hasOne(TherapistSupervisor::class);
    }
}

Zerion Mini Shell 1.0