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

eLekun's avatar

export to excel with laravel excel

hello friends, I am implementing excel download of a table with paging, how is it possible to export only the records that are shown on the page that the user is on. Thank you

0 likes
6 replies
vincent15000's avatar

The page on which the user is on ... do you mean the Excel sheet ?

vincent15000's avatar

@eLekun Oh you mean the page of the pagination.

You have to send a request with the page number (pagination page) and retrieve that page in a controller to export the collection to Excel.

eLekun's avatar

@vincent15000 Yes, exactly, but I don't quite understand how the query would be to export the records of that page.

1 like
eLekun's avatar
eLekun
OP
Best Answer
Level 1

I have solved it in the following way in the controller, thanks!

$users = User::paginate(5, ['*'], 'page', $pageNumber);

1 like

Please or to participate in this conversation.