Make Money With Laravel Query Builder
I have a connection in laravel 5.1 and it works great, but I am returning an array with each result of my connection. Is there a way to return results with nested array join results inside my main select query, or should it be something I do in PHP after getting the results?
$single = $this->db->table($this->table)
->leftJoin("ootd_clothing", "ootd_clothing.ootd_id", "=" ,"$this->table.id")
->leftJoin("users", "users.id", "=", "$this->table.user_id")
->where("$this->table.slug", "=", $slug)
->select("$this->table.name AS ootd_name", "$this->table.image_path", "$this->table.slug", "$this->table.description", "users.name AS user_name", "ootd_clothing.item", "ootd_clothing.brand")
->get();
The result I am getting:
array:5 [▼
0 => {#158 ▶}
1 => {#159 ▶}
2 => {#160 ▶}
3 => {#161 ▶}
4 => {#162 ▶}
]
The result that I would like:
array:1 [
'id': 1,
'joinResults':array:5 [▼
0 => {#158 ▶}
1 => {#159 ▶}
2 => {#160 ▶}
3 => {#161 ▶}
4 => {#162 ▶}
]
]
+3
source to share
No one has answered this question yet
Check out similar questions: