I have 2 tables:
Services
id | name | ...
Prices
id | service_id | day | time | price
One service can have many prices (by day in week and time in day).
When I try to get my object and turn it into array this is how it looks now:
$service = Service::with('prices')->find(1);
array
'id' => string '1'
'name' => string 'Test'
'prices' =>
array
0 =>
array (size=7)
'id' => string '1'
'service_id' => string '1'
'day' => string '1'
'time' => string '0'
'price' => string '50.00'
1 =>
array (size=7)
'id' => string '2'
'service_id' => string '1'
'day' => string '1'
'time' => string '1'
'price' => string '50.00'
...
I would like to get this service object looking like this:
array
'id' => string '1'
'name' => string 'Test'
'prices' =>
array
1 => array
'0' => '100.00'
'1' => '100.00'
...
'23' => '450.00'
2 => array
'0' => '100.00'
'1' => '100.00'
...
'23' => '450.00'
In another words, I would like that my relation returns first array that contains days (1-7), and each day is array with time (0-23) in that day.
What is the best practice to do that?