First of all I am new to laravel.
This is my controller
$itemsList=Items::all()->where('shop_id',$request->shop_id);
return response()->json(['data'=>$itemsList]);
This is the response
{
"data": {
"10": {
"id": 11,
"shop_id": 1,
"title": "Test",
"price_nd": 12,
"price_wd": 10,
"updated_at": "2019-11-14 00:00:00",
"created_at": "2019-11-14 00:00:00"
},
"11": {
"id": 12,
"shop_id": 1,
"title": "Test",
"price_nd": 12,
"price_wd": 10,
"updated_at": "2019-11-14 00:00:00",
"created_at": "2019-11-14 00:00:00"
},
"14": {
"id": 15,
"shop_id": 1,
"title": "Test",
"price_nd": 12,
"price_wd": 10,
"updated_at": "2019-11-14 00:00:00",
"created_at": "2019-11-14 00:00:00"
}
}
}
The problem is I want to return an array list of the items
I tried many approached but I don't know what is the problem or what I am missing
Try. Use get() method .
get() and all() both get same output but
all() method not useful for use where condition.
get() method can useful to use other conditions
$itemsList=Items::where('shop_id',$request->shop_id)->get();
return response()->json(['data'=>$itemsList]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With