File: /var/www/html/sarvodayahospital/app/Models/Award.php
<?php
namespace App\Models;
use App\Scopes\isPublishedScope;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class Award extends Model
{
protected $with = ['media'];
protected static function booted()
{
return static::addGlobalScope(new isPublishedScope());
}
public function getDateAttribute($value)
{
return Carbon::parse($value)->format('M d, Y');
}
public function media()
{
return $this->hasManyThrough(
Media::class,
MediaMorph::class,
'related_id',
'id',
'id',
'upload_file_id'
)
->where('related_type', 'awards')
->where('field', 'Photo')
->orderBy('order')
->select('upload_file_morph.id', 'name', 'url', 'formats');
}
public function seoComponent()
{
return $this->hasOneThrough(
SEOComponent::class,
AwardComponent::class,
'award_id',
'id',
'id',
'component_id'
)->where('field', 'SEO')
->where('component_type', 'components_seo_seos');
}
}