I have two tables, page and edit.
page
+----+-----------+
| id | page_name |
+----+-----------+
| 1 | page |
+----+-----------+
edit
+----+---------+------+
| id | page_id | name |
+----+---------+------+
| 1 | 1 | home |
| 1 | 1 | side |
+----+---------+------+
Right now I have a relationship defined linking the two together. It returns something like this:
array(
'id' => 1,
'page_name' => 'page',
'edit' => array(
0 => array(
'id' => 1,
'page_id' => 1,
'name' => 'home'
),
1 => array(
'id' => 2,
'page_id' => 1,
'name' => 'side'
)
)
)
I would like to be able to set the key of the edit array to the value of a certain column. Like so:
array(
'id' => 1,
'page_name' => 'page',
'edit' => array(
'home' => array( // the key is the name column
'id' => 1,
'page_id' => 1,
'name' => 'home'
),
'side' => array( // the key is the name column
'id' => 2,
'page_id' => 1,
'name' => 'side'
)
)
)
How can I do this using Laravel's query builder? Or is this something I'll have to format & structure manually with a loop?