分页在laravel数据表中

时间:2016-05-02 07:34:20

标签: laravel laravel-5 laravel-5.1 laravel-5.2

我是Laravel的新手,我需要在查询时实现Pagination。 下面是我发送的查询,接下来要实现的目标。

$arrAirlines = DB::table("(SELECT air.airline_id, air.title FROM `tbl_com_airlines_airports` as aa
                        left join tbl_com_airlines as air ON air.airline_id = aa.airline_id
                        where aa.country_id ='".$countryId."' and aa.is_deleted ='0' and air.org_id ='".$orgId."'
                        and (Select count(*) from tbl_com_airlines_airports  where aa.is_domestic ='1')>1)")
                       ;

2 个答案:

答案 0 :(得分:1)

查询可以写成

DB::table('tbl_com_airlines_airports as aa')
            ->leftjoin('tbl_com_airlines as air','air.airline_id','=','aa.airline_id')
            ->select('air.airline_id','air.title','aa.*')
            ->where('aa.country_id','=',$countryId)
            ->where('aa.is_deleted','=',0)
            ->where('aa.is_domestic','=',1)
            ->where('air.org_id','=',$orgId)
            ->paginate(10);

答案 1 :(得分:0)

您最好查看官方laravel的文档:Laravel Pagination 尝试一下,如果你遇到任何其他问题 - 更好地澄清它以获得相关答案:)