Как выполнить необработанные запросы с помощью Laravel 5.1?

Поэтому у меня есть этот крошечный запрос для работы в моей базе данных, и он отлично работает в MySQL Workbench. В принципе, SELECT с LEFT JOIN и UNION с LEFT JOIN снова.

SELECT cards.id_card, cards.hash_card, cards.`table`, users.name, 0 as total, cards.card_status, cards.created_at FROM cards LEFT JOIN users ON users.id_user = cards.id_user WHERE hash_card NOT IN ( SELECT orders.hash_card FROM orders ) UNION SELECT cards.id_card, orders.hash_card, cards.`table`, users.name, sum(orders.quantity*orders.product_price) as total, cards.card_status, max(orders.created_at) FROM menu.orders LEFT JOIN cards ON cards.hash_card = orders.hash_card LEFT JOIN users ON users.id_user = cards.id_user GROUP BY hash_card ORDER BY id_card ASC 

В попытке перевести его в Laravel, без успеха.

 $cards = Card::selectRaw('cards.id_card, cards.hash_card ,cards.table, users.name, 0 as total, cards.card_status, cards.created_at as last_update') ->leftJoin('users','users.id_user','=','cards.id_user') ->whereNotIn( 'hash_card', Order::select('orders.hash_card')->get() ) ->union( Order::selectRaw('cards.id_card, orders.hash_card, cards.table, users.name, sum(orders.quantity*orders.product_price) as total, cards.card_status, max(orders.created_at) as last_update') ->leftJoin('cards','cards.hash_card','=','orders.hash_card') ->leftJoin('users','users.id_user','=','cards.id_user') ) ->groupBy('hash_card') ->orderBy('cards.id_card','asc') ->get(); по $cards = Card::selectRaw('cards.id_card, cards.hash_card ,cards.table, users.name, 0 as total, cards.card_status, cards.created_at as last_update') ->leftJoin('users','users.id_user','=','cards.id_user') ->whereNotIn( 'hash_card', Order::select('orders.hash_card')->get() ) ->union( Order::selectRaw('cards.id_card, orders.hash_card, cards.table, users.name, sum(orders.quantity*orders.product_price) as total, cards.card_status, max(orders.created_at) as last_update') ->leftJoin('cards','cards.hash_card','=','orders.hash_card') ->leftJoin('users','users.id_user','=','cards.id_user') ) ->groupBy('hash_card') ->orderBy('cards.id_card','asc') ->get(); 

Я получаю ошибку

ОшибкаException в строке Builder.php 1249: Неопределенное свойство: Illuminate \ Database \ Eloquent \ Builder :: $ привязки

Как я могу выполнить полностью сырой запрос в Laravel или правильно написать запрос в Laravel?

Related of "Как выполнить необработанные запросы с помощью Laravel 5.1?"

Я нашел решение в этой теме, и я кодирую это:

 $cards = DB::select("SELECT cards.id_card, cards.hash_card, cards.`table`, users.name, 0 as total, cards.card_status, cards.created_at as last_update FROM cards LEFT JOIN users ON users.id_user = cards.id_user WHERE hash_card NOT IN ( SELECT orders.hash_card FROM orders ) UNION SELECT cards.id_card, orders.hash_card, cards.`table`, users.name, sum(orders.quantity*orders.product_price) as total, cards.card_status, max(orders.created_at) last_update FROM menu.orders LEFT JOIN cards ON cards.hash_card = orders.hash_card LEFT JOIN users ON users.id_user = cards.id_user GROUP BY hash_card ORDER BY id_card ASC");