File: /var/www/html/sarvodayahospital/app/Models/PreventiveHealthCheckup.php
<?php
namespace App\Models;
use App\Scopes\isActiveScope;
use App\Scopes\isPublishedScope;
use Illuminate\Database\Eloquent\Model;
class PreventiveHealthCheckup extends Model
{
protected $table = 'preventive_health_checkups';
protected $with = ['media'];
protected static function booted()
{
static::addGlobalScope(new isActiveScope());
static::addGlobalScope(new isPublishedScope());
}
public function getPackageNameAttribute($value)
{
return html_entity_decode($value);
}
public function getDescriptionAttribute($value)
{
return html_entity_decode($value);
}
public function hospitals()
{
return $this->belongsToMany(
Hospital::class,
'preventive_health_checkups__hospitals',
'preventive_health_checkup_id',
'hospital_id'
)->select('preventive_health_checkups__hospitals.id', 'HospitalName', 'Slug');
}
public function media()
{
return $this->hasOneThrough(
Media::class,
MediaMorph::class,
'related_id',
'id',
'id',
'upload_file_id'
)
->where('related_type', 'preventive_health_checkups')
->where('field', 'PackageIcon')
->orderBy('order')
->select('upload_file_morph.id', 'name', 'url', 'formats');
}
public function seoComponent()
{
return $this->hasOneThrough(
SEOComponent::class,
PreventiveHealthCheckupComponent::class,
'preventive_health_checkup_id',
'id',
'id',
'component_id'
)->where('field', 'SEO')
->where('component_type', 'components_seo_seos');
}
}