Answer the question
In order to leave comments, you need to log in
Laravel get data array from db sorted by table columns?
There is a table in the database with the following data
['id', 'user_id', 'date', 'number', 'text']
['1', '1', '2019-10-30', '11', ' bla bla bla 1']
['2', '1', '2019-10-30', '12', 'bla bla bla 2']
['3', '1', '2019-10-31' , '11', 'bla bla bla 3']
Is it possible to get the following result when querying this table in the database
[
'2019-10-30' => [
'11' => ['1', '2019- 10-30', '11', 'bla bla bla 1']
'12' => ['2', '2019-10-30', '12', 'bla bla bla 2']
]
'2019-10-31' => [
'11' => ['3', '2019-10-31', '11', 'bla bla bla 3']
]
]
those. the key will be the name of the column, but the array in the array
is something like this, but 2 keyBy is needed by date and number
$query = Post::where('user_id', 1)->get()->keyBy('date' )->toArray();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question