Reputation: 131
I would like to transform the result of an Eloquent query into a single array of strings.
What my query currently gives: (I apply a ->toArray() to initial query to get that :)
array:2 [▼
0 => array:1 [▼
"title" => "User"
]
1 => array:1 [▼
"title" => "Premium"
]
]
What I would like it to give me:
['User', 'Premium'];
My query :
Rank::where('strength', '<', $this->rank->strength)->select('title')->get();
Thanks in advance
Upvotes: 0
Views: 90
Reputation: 706
If you want exactly same array response instead of collection, You can add toArray() function at the last
$ranks = Rank::where('strength', '<', $this->rank->strength)
->pluck('title')->toArray();
Upvotes: 1