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
php laravel laravel-5 query-builder


source to share


No one has answered this question yet

Check out similar questions:

917
mysql_fetch_array () / mysql_fetch_assoc () / mysql_fetch_row () / mysql_num_rows etc ... expects parameter 1 to be resource or result
451
How do I get the Query Builder to output its raw SQL query as a string?
371
Best Practices for Individual Helpers in Laravel 5
4
How to get database resource instead of array from Laravel Query Builder?
2
Laravel 5 query structure to get nested array result
1
Laravel Query Builder. Returning nested structured data
0
Laravel / MySQL query raw
0
Complicated MySQL inner join query with Laravel Query Builder
0
Can't get desired result when loading Laravel data
0
Laravel 5.5 pivot merge to get pivots with MySQL main result



All Articles
Loading...
X
Show
Funny
Dev
Pics