File: /var/www/html/sarvodayahospital/app/Models/RareCase.php
<?php
namespace App\Models;
use App\Scopes\isPublishedScope;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class RareCase extends Model
{
protected $hidden = ['published_at', 'created_by', 'updated_by', 'created_at', 'updated_at'];
protected static function booted()
{
return static::addGlobalScope(new isPublishedScope());
}
public function getPublishedAtAttribute($value)
{
return Carbon::parse($value)->format('M d, Y');
}
public function specialities()
{
return $this->belongsToMany(
Speciality::class,
'rare_cases__specialities',
'rare_case_id',
'speciality_id'
);
}
public function doctors()
{
return $this->belongsToMany(
Doctor::class,
'rare_cases__doctors',
'rare_case_id',
'doctor_id'
);
}
public function seoComponent()
{
return $this->hasOneThrough(
SEOComponent::class,
RareCaseComponent::class,
'rare_case_id',
'id',
'id',
'component_id'
)->where('field', 'SEO')
->where('component_type', 'components_seo_seos');
}
public function hospital()
{
return $this->belongsTo(Hospital::class, 'hospital');
}
}