I have three tables(users, cars and pivot table photos) and many to many polymorphic relationship between them..
photos table
I have collection of photos and when I want to display $car->photo->file I am getting this error:
Property [file] does not exist on this collection instance.
I am calling inside blade file {{$car->photo->file}} $car is variable of $cars which I foreach from my controller, ->photo is the name of relationship between car and photo and ->file is the name of the column inside photos table.
My User model: this is for images which are related to profile avatars
public function photo() {
return $this->morphMany('App\Models\Photo', 'imageable');
}
My Car model:
public function photo() {
return $this->morphMany('App\Models\Photo', 'imageable');
}
My Photo model:
public function imageable() {
return $this->morphTo();
}