See last reply, last example here,
https://laracasts.com/discuss/channels/guides/getpdo-usage
I would never do such a query in eloquent or query Builder like above.
the second I have to use the word Raw, I do a regular query.
Will boot up laptop shortly and give another example from cronix.
Here's another good example: (cronix provided)
https://laracasts.com/discuss/channels/laravel/sql-native-to-query-builder
quote
$bindings = [
'product_type_id' => 1,
'service_sub_type_id' => 2,
'school_id' => 57,
'status_id1' => 2,
'status_id2' => 3
];
$users = DB::select('SELECT DISTINCT CONCAT(u.last_name, ", ", u.first_name ) AS full_name, ci.created_at AS date_purchase
FROM cart_items AS ci
LEFT JOIN products AS p ON ci.product_id = p.id
LEFT JOIN carts AS c ON ci.cart_id = c.id
LEFT JOIN `status` AS s ON ci.status_id = s.id
INNER JOIN users AS u ON c.user_id = u.id
INNER JOIN school_users AS su ON u.id = su.user_id
INNER JOIN
(
SELECT MAX(created_at) AS created_at1, cart_id
FROM cart_items
GROUP BY `cart_id`
)p2 ON ci.cart_id = p2.cart_id AND ci.created_at = p2.created_at1
WHERE p.product_type_id = :product_type_id AND p.service_sub_type_id = :service_sub_type_id AND su.school_id = :school_id AND ci.status_id = :status_id1 OR ci.status_id = :status_id2
ORDER BY ci.created_at DESC', $bindings);
unquote
Note however db facade returns also array of objects, but getPdo() you are in full control, it's the PDO instance directly. so you can:
$quy = $sth->fetchAll(\PDO::FETCH_ASSOC);
$quy = $sth->fetch(\PDO::FETCH_ASSOC); // just one
//or
$quy = $sth->fetchAll(\PDO::FETCH_OBJ);