Why is Eloquent returning a different result if retrieving All and using a where clause?
When I use the following retrieve:
$items = Item::All()->where('user_id', '=', Auth::user()->id);
I get (no idea of what the ‘0’ and ‘2’ identifiers are):
"items": {
"0": {
item1data
},
"2": {
item2data
}
}
But when I use:
$items = Item::where('user_id', '=', Auth::user()->id)->get();
I get the following array:
"items": [
{
item1data
},
{
item2data
}
]
The second is what I need, so I can send it back as a Json response, but I’m curious of why the results are being different.
from Laravel Questions and Answers https://laravelquestions.com/laravel/why-is-eloquent-returning-a-different-result-if-retrieving-all-and-using-a-where-clause/
via Lzo Media
No comments:
Post a Comment