简体   繁体   中英

Raw query to Eloquent. laravel

Paginator's per page not work. all results displayed. i need raw sql to Eloquent. pls help. Eloquent can paginate.

SELECT p.id, p.name, p.image_filename, p.contact, p.price, p.created_at FROM product p
INNER JOIN
category c ON p.category_id = c.id AND (c.lft BETWEEN '.$left.' AND '.$right.')
ORDER BY p.created_at DESC 



$products = DB::select(DB::raw($query)); 
$pagination = Paginator::make($products, count($products), 5);
$between = array($left, $right);
Product::join('category', function($join) {
    $join->on('product.category_id', '=', 'category.id');
})
->whereBetween('category.lft', $between)
->select('product.id', 'product.name', 'product.image_filename', 'product.contact', 'product.price', 'product.created_at')
->orderBy('product.created_at', 'desc')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM