Hi im new to Laravel and im just trying to work out the query builder.
If i wanted to do this query :
'SELECT * FROM product INNER JOIN price ON product.productid = price.productid LEFT JOIN purchaseitem ON product.productid = purchaseitem.productid WHERE product.name = '.$keyword.' AND purchaseitem.datestart NOT BETWEEN "2014-01-06" AND "2014-01-07" GROUP BY product.productid HAVING COUNT( purchaseitem.productid ) < product.quantity LIMIT 0 , 30'
Would i be on the right lines with something like this :
DB::table('product') ->join('price','product.productid','=','price.productid') ->leftJoin('purchaseitem','product.productid','=','purchaseitem.productid') ->where('product.name','=','Superior King Room') ->whereNotBetween('purchaseitem.datestart', array(2014-01-06, 2014-01-07) ->groupBy(function($query) { $query->having('purchaseitem.productid', '<', 'product.quantity') })->get();
If anyone has any ideas it would be a big help.
Thanks.
You may use the following code:
dd($your_query->toSql());
Then access the page and your code will halt execution and dump the query as SQL syntax.
By the way, for this exact query you exemplified, the following code works:
DB::table('product')
->join('price', 'product.productid', '=', 'price.productid')
->leftJoin('purchaseitem', 'product.productid', '=', 'purchaseitem.productid')
->where('product.name', '=', 'Superior King Room')
->whereNotBetween('purchaseitem.datestart', array('2014-01-06', '2014-01-07'))
->groupBy('product.productid')
->having(DB::raw('count(`purchaseitem`.`productid`)'), '<', 'product.quantity')
->take(30);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community