Pass Mysql query to Eloquent Laravel

Asked

Viewed 166 times

1

I have a query that when passing to eloquent returns me syntax error.

SELECT order_id FROM timelines
WHERE order_id NOT IN (SELECT order_id FROM timelines WHERE supplier_approved_id) AND supplier_id = 2
GROUP BY order_id

Eloquent:

Timeline::select('order_id')
    ->whereRaw('order_id NOT IN', [], '( SELECT order_id FROM timelines WHERE supplier_approved_id )')
    ->where('supplier_id', 2)
    ->groupBy('order_id')
    ->get();
  • 1

    Instead of getting to use toSql() in Eloquent, this will return the SQL mounted by Eloquent, then you compare it to your query above and see what’s wrong.

1 answer

2


I may be wrong but I think the mistake is in your whereRaw. Try without separating the array, as below:

->whereRaw('order_id NOT IN (SELECT order_id FROM timelines WHERE supplier_approved_id )')

  • 1

    I could have sworn I tried. It worked, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.