want to use to get multiple rows where the foreign key values (product_id) are the same so that I can get only the relevant rows. The problem is laravel is throwing this error: Undefined index: product_id. But it's there in the table and this error is only thrown for the foreach loop. Outside the loop the request executes flawlessly. What do you advise? Thanks in advance.
foreach($product_ids as $id) {
$data = Image::where('product_id', '=', $id)->get();
array_push($images, $data);
}
You could define a relationship between the two then do: $product = Product::find($id); if (!$product) { // throw error } $images[] = $product->images;
Solved
Right here
Обсуждают сегодня