How can i do Laravel pagination for multiple table results?

Question

In Laravel, I have multiple table results from controller to view. I need to do pagination for this set of results. How can I do that?

I have these many results from different tables

return View::make('view')->with('data_array', $data_array)->with('count', $count)->with('paginate', $paginate);

data_array has array result from multiple tables.

$employee_detail = EmployeeDetail::Select('employee_id', 'unique_type_id', 'unique_number')->get()->toArray();
        $paginate = EmployeeDetail::paginate(5);        
        $count = EmployeeDetail::Select('employee_id', 'unique_type_id', 'unique_number')->count();

        $data_array = array();
        $i = 0;
        foreach ($employee_detail as $employeeKey => $employeeValue) {
            $kiosk_id = $employeeValue['employee_id'];
            $data_array[$i]['kiosk_id'] = $kiosk_id;
            $package_id = $employeeValue['unique_type_id'];
            $unique_number = $employeeValue['unique_number'];
            $data_array[$i]['unique_number'] = $unique_number;
            $carrier_details = CarrierDetails::Select('package_name', 'carrier_type_id')->where('id', '=', $package_id)
                ->get()
                ->toArray();
            foreach ($carrier_details as $packageDetailskey => $packageDetailsvalue) {
                $package_name = $packageDetailsvalue['package_name'];
                $data_array[$i]['package_name'] = $package_name;
                $carrier_type = $packageDetailsvalue['carrier_type_id'];
                $carrier_details = CarrierType::Select('carrier_name')->where('id', '=', $carrier_type)->get();
                foreach ($carrier_details as $carrierDetailsKey => $carrierDetailsValue) {
                    $carrier_name = $carrierDetailsValue['carrier_name'];
                }
                $data_array[$i]['carrier_name'] = $carrier_name;
                $i ++;
            }

please give me the suggestions.

Thanks :)


Show source
| laravel   | php   | mysql   | pagination   2017-01-07 15:01 1 Answers

Answers to How can i do Laravel pagination for multiple table results? ( 1 )

  1. 2017-01-07 15:01

    You have two options here:

    1. Create a paginator manually

    This tutorial should help you.

    1. Rewrite your code to use Eloquent relationships and use with() or load(). In this case you'll be able to use paginate() method.

    If I were you I'd choose the second one.

Leave a reply to - How can i do Laravel pagination for multiple table results?

◀ Go back