请帮助我的家伙使用分页类的laravel与数据库原始复杂的查询...
尝试了一些技巧来获得结果与laravel分页,但由于查询的复杂性,它创造了问题,我
$data = DB::select(DB::raw("SELECT DISTINCT c.id, c.name, c.active, c.image, c.created_at, (SELECT COUNT(*) FROM categories WHERE c.id=parent_id) AS subcat_count, (SELECT COUNT(*) FROM post_ads WHERE c.id=cat_id) AS postad_count FROM categories AS c LEFT OUTER JOIN categories AS subc ON c.id = subc.parent_id LEFT OUTER JOIN post_ads AS postadc ON c.id = postadc.cat_id WHERE c.parent_id=0 ORDER BY c.name ASC LIMIT 9"));
2条答案
按热度按时间hivapdat1#
使用限制和偏移而不是分页,我有同样的问题,并解决了它通过使用限制和偏移。
a2mppw5e2#
你可以使用长度感知分页器分页,在你的控制器中这样做,