I have two tables. 1.products 2.product_images.
Field of products Table: id,product_name,created_at,updated_at
Field of product_images Table: id,product_id,product_image,created_at,updated_at
products table has OnetoMany relationship with product_images table.
So in the Product model I have defined :
public function productImage()
{
return $this->hasMany(Product_image::class,'product_id');
}
Now I want to to get all the data of product id 1 from both tables.
So I have this code below:
App\Product::find(1)->productImage
Result Set is:
Illuminate\Database\Eloquent\Collection {#689
all: [
App\Product_image {#679
id: 1,
product_id: 1,
product_image: "1494787942_download (1).jpg",
created_at: "2017-05-14 18:52:22",
updated_at: "2017-05-14 18:52:22",
},
],
}
But I am not getting the product_name. What will be the solution? Thanks.