I have two tables:
images
-id
-name
-imageable_id
-imageable_type
article
-id
-title
....
-image_id
I've created a images function to get all images that returns this relationship:
public function images()
{
return $this->morphMany('App\Image', 'imageable');
}
and that works great, but I also want to have a mainImage function that will use image_id on article to get the image with that id from the image table. I've tried
hasOne('App\Image', 'id', 'image_id')
With this code
$imageId = $request->input('mainImage');
if(!empty($imageId)){
$image = Image::find($imageId);
$listing->mainImage()->save($image);
}
And that doesn't seem to set image_id to anything but null. Thank you in advance for any help!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community