There are two packages tables and packages_description. In the first title, the price. In another package_id, a description. Wrote a request for the withdrawal of packages and their descriptions. Issued:

[items:protected] => Array ( [0] => stdClass Object ( [id] => 7 [title] => Старт [price] => 500 [order] => 1 [addition] => [description] => 1 вариант рекламного объявления ) [1] => stdClass Object ( [id] => 7 [title] => Старт [price] => 500 [order] => 1 [addition] => [description] => Запуск 1 рекламного объявления ) [2] => stdClass Object ( [id] => 7 [title] => Старт [price] => 500 [order] => 1 [addition] => [description] => отчет ) [3] => stdClass Object ( [id] => 8 [title] => Бизнес [price] => 1500 [order] => 2 [addition] => [description] => отчет ) [4] => stdClass Object ( [id] => 9 [title] => Индивидуальный [price] => 5000 [order] => 3 [addition] => от [description] => ) ) 

The request itself:

 $packages = DB::table('packages') ->select(DB::raw('packages.*, packages_description.description as description')) ->leftJoin('packages_description', 'packages.id', '=', 'packages_description.package_id') ->groupBy('id', 'description') ->get(); 

How to display:

  ( [id] => 7 [title] => Старт [price] => 500 [order] => 1 [addition] => [description] => array( '1 вариант рекламного объявления', 'Запуск 1 рекламного объявления', 'отчет') ) 

How to write a request?

    1 answer 1

     [description] => array( '1 вариант рекламного объявления', 'Запуск 1 рекламного 

    In laravel you can make a method:

     public function getDescriptionAttribue(){ return explode(',', $this->description); } 

    Add it to the field

     protected $appends = ['description'] 

    This is how to disassemble data from the database. Now the query: you need to apply grouping on the field for this you can use a subquery. For example:

     select t.id, t.title, t.order, t.addition, group_concat(t.description) from ( select id, title, order, addition, description from packages where id = 7 group by id, title, order, addition, description ) t 

    It remains only to put this request on ORM.