如何在Laravel中对Raw Query进行分页?

时间:2016-12-24 10:56:15

标签: php laravel pagination laravel-5.2

我在一个大型列表中写了一个原始查询表单。所以为此,我想使用分页。但对于原始查询->paginate(5);

以下是我使用的示例原始查询:

public function managementReport(){
        $managementReport = DB::select(DB::raw("SELECT members.name as name, 
                members.card_no as card_no, members.joining_date as joining_date,
                salary_terms.designation as designation, salary_terms.main_salary as main_salary,
                salary_terms.basic as basic,salary_terms.house_rent as house_rent,
                salary_terms.medical as medical,salary_terms.conveyance as conveyance,
                salary_terms.food as food,monthly_payrolls.days_on_month as days_on_month,
                monthly_payrolls.working_days as working_days,
                ((salary_terms.basic*monthly_payrolls.leave_without_pay)/monthly_payrolls.working_days) as absent,
                (salary_terms.main_salary - ((salary_terms.basic*monthly_payrolls.leave_without_pay)/monthly_payrolls.working_days)) 
                as gross_pay,monthly_payrolls.deduction,(salary_terms.main_salary -( ((salary_terms.basic*monthly_payrolls.leave_without_pay)/monthly_payrolls.working_days)+monthly_payrolls.deduction)) 
                as net_pay FROM members INNER JOIN salary_terms on members.id = salary_terms.member_id INNER JOIN 
                monthly_payrolls on salary_terms.id = monthly_payrolls.salary_term_id 
                WHERE salary_terms.is_management='1'"));
                return view("Report::management",compact('managementReport'));
        }

那么如何在laravel中使用原始查询实现paginate()

1 个答案:

答案 0 :(得分:1)

尝试create pagination manually使用数据库数据。

也许this tutorial也会有所帮助。