How to add dynamic pagination to LaravelExcel

I want to download some data from view using LaravelExcel. So here is my Export Class:

class StudentExportView implements FromView
    * @return IlluminateSupportCollection
    public function view(): View
        $student = new Student();
        $students = $student->searchStudents()->paginate(20);
        $custom = new Student();
        $customs = $custom->all();
        return view('admin.students.custom', compact('students','customs'));

As you can see I have used paginate(20) because the data that I’m going to download is so LARGE, and I have to use this pagination.

Then at the Controller, I added this method:

public function export_view()
        return Excel::download(new StudentExportView, 'studentlist.csv');

And the route that calls this method goes here:

Route::get('export_view','[email protected]_view')->name('students.export_view');

But I need to make this dynamically. So how to do this for exporting data.

Source: Laravel

Leave a Reply