1

How can I build the following MySQL query using Laravel-5?

select orders.*, oi.items from orders 
inner join (select order_id, group_concat(item_name SEPARATOR ', ') as items 
from orders_items group by order_id) as oi on oi.order_id = orders.id;

EDIT

The suggested link did not resolve my problem, however I did find a solution and will post it below for others.

0

1 Answer 1

2
$order  = $order->select('orders.*', 'oi.items');
$order->join(DB::raw('(select order_id, group_concat(item_name SEPARATOR ",") as items from orders_items group by order_id) as oi'), function($join)
{
    $join->on('oi.order_id', '=', 'orders.id');
});
$order->whereRaw('find_in_set ("'.$value.'", oi.items)');

$rows = $order->get();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.