That is how collections work at the moment and it's just a presentation of the data. However when you access the data you will never see the all key at all!
Mar 19, 2018
4
Level 2
What is the purpose of the `all` key in an eloquent get query
Say I have the following query Bed::where('user_id', 1)->get()
all: [
App\Bed {#796
id: 1,
user_id: 1,
name: "sgdffd",
gender: "male",
type: "single",
status: "available",
created_at: "2018-03-19 07:53:51",
updated_at: "2018-03-19 07:53:51",
},
],
whats the point of the all key wouldn't it be simpler to just return an array of model data?
[
App\Bed {#796
id: 1,
user_id: 1,
name: "sgdffd",
gender: "male",
type: "single",
status: "available",
created_at: "2018-03-19 07:53:51",
updated_at: "2018-03-19 07:53:51",
},
],
Level 88
Yeah, Laravel will automatically convert it to the right format. So for your views to an array and for api responses to json using that array.
Let me know if you have more questions!
Please or to participate in this conversation.