I cannot get the relationship belongsToto work (or I'm using the wrong relationship).
My database structure (simplified):
pages
id | title | main_image
-----------------------
1 | Test | 5
mass media
id | filepath
-----------------------
5 | uploads / test.jpg
So, I want to be able to do $page->main_image, and it will return me an instance of the Media model, so I could use $page->main_image->filepath, etc.
In the model Page, I have the following:
public function main_image()
{
return $this->belongsTo('App\Modules\Media\Models\Media', 'id', 'main_image');
}
But when I do $page->main_image, I just get int 5. Am I using the wrong relationship here?
Thank!
source
share