Basically, a SELECT with LEFT JOIN and UNION with LEFT JOIN again. >leftJoin('cards','cards.hash_card','=','orders.hash_card')ĮrrorException in Builder. How to execute raw queries with Laravel 5.1 Ask Question Asked 7 years, 9 months ago Modified 7 months ago Viewed 325k times Part of PHP Collective 113 So I have this tiny query to run on my DB and it works fine in MySQL Workbench. 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') >whereNotIn( 'hash_card', Order::select('orders.hash_card')->get() ) Instead of using the DB::raw method, you may also use the following methods to insert a raw expression into various parts of your query. $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') In tried to translate it to Laravel, with no success. Sum(orders.quantity*orders.product_price) as total, Utilize the feature of ORM not raw statement if possible. WHERE hash_card NOT IN ( SELECT orders.hash_card FROM orders ) 13k 22 79 160 1 Why are you essentially deconstructing Laravel's query builder into an insecure function Devon Bessemer at 14:07 create more generic kind of method for your joins and pass parameters accordingly. Im trying to use Eloquent ORM from Laravel in my own legacy project. So I have this tiny query to run on my DB and it works fine in MySQL Workbench.īasically, a SELECT with LEFT JOIN and UNION with LEFT JOIN again.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |