Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

swapnilmanew's avatar

How to export only paginated / filtered data into excel ?

HEllo Devs,

I have millions of companies data into the database. I have applied filters for that data.

So what i want to do is when i apply search filters to that data it gives me data and it is devided into pages. So i want to export only filtered data into excel including paginated data.

suppose I have 1000 records and devided 100 on each page upto 10 then i want to export those 1000 records. How can I do this ?

 $query = tbl_company::query();

        if ($req->has('state')) {
            $query->whereIn('state', $req->input('state'));
        }

        if ($req->has('district')) {
            $query->whereIn('district', $req->input('district'));
        }
 $data = $query->paginate(100);
        return view('/admin/company/index', compact('data',));
0 likes
4 replies
Tray2's avatar

The simplest would be to just run the query without the pagination, then you would get the desired result.

Tray2's avatar

@swapnilmanew I don't know what lakhs and crores mean, but to generate a excel file you do that on the server with a queued job, and when that job is done you send a broadcast or an email with the link to the generated excel file.

Sinnbeck's avatar

Just to make it clear. You only want the first 1000 records. And those should be split up into different sheets in excel, with 100 rows on each sheet?

Please or to participate in this conversation.