Situation
I have the following code to get all data as an array:
Data::select('id', 'text')->get()->toArray();
This will return the data in the following format:
array:1 [ 0 => array:2 ["id" => "1""text" => "Stack" ] 1 => array:2 ["id" => "2""text" => "Overflow" ]]
But I want only the values as a regular array (no keys/associative array) so the array is not converted to an object when I convert it to JSON:
array:1 [ 0 => array:2 [ 0 => "1" 1 => "Stack" ] 1 => array:2 [ 0 => "2" 1 => "Overflow" ]]
Inadequate solutions
I know I can convert this with a loop and use array_values()
, but the former is not a one liner while the second works only for one level and not for arrays of arrays.
Also I'm looking for a way to "configure" Eloquent/Query Builder, and not a method to convert the once returned results.
Questions
Is there a setting or a way I can do this with Eloquent/Query Builder?