how to file get with base url in laravel 8 using relation

Viewed 21
$data = Course::with('subject' , 'module' , 'lession' ,'lecture_audio' , 'lecture_text', 'lecture_document', 'lecture_image' ,'lecture_other_video' , 'course_video' , 'video' ,'add_assessment' , 'add_homework','text_homework' , 'video_homework')->where('id' , $request->course_id)->get();
return $data;
1 Answers

you can simply add this function in each model that has a file

public function getImageAttribute($value){
    return asset('images' . $value);
}

then you replace the images word in the asset with the path you want, and change the Image in getImageAttribute with the column name, and if it's something like user_image you make it getUserImageAttribute

Related