File: /var/www/html/sarvodayahospital/app/Models/CSR.php
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class CSR extends Model
{
protected $table = 'csrs';
protected $with = ['media'];
public function getCSRDateAttribute($value)
{
return Carbon::parse($value)->format('d-m-Y');
}
public function media()
{
return $this->hasOneThrough(
Media::class,
MediaMorph::class,
'related_id',
'id',
'id',
'upload_file_id'
)
->where('related_type', 'csrs')
->where('field', 'Image')
->orderBy('order')
->select('upload_file.id', 'name', 'url', 'formats');
}
}