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

SupunSam's avatar

How to add Alert to Laravel Excel Export

I am using maatwebsite/excel package in my project and it is working fine. Now I want to add an alert when I click on the export button and if the export is successful.

Controller:

public function jobsExport()
{
        Alert::toast('Jobs Exported into Excel', 'info');
        return Excel::download(new JobsExport, 'Jobs-' . Carbon::now() . '.xlsx', \Maatwebsite\Excel\Excel::XLSX);
}
        

Route:

Route::get('/jobsExport', 'JobController@jobsExport')->name('jobsExport');

Button(in View)

<a href="{{route('jobsExport')}}" class="btn btn-secondary" download>
                Export Excel
</a>

I have tried to use HTTP responses with this matter but unable to find a solution there. I am not that fluent in Laravel. Kindly Help me with this problem.

0 likes
2 replies
jove's avatar

Redirect back with a message?

Flash a message?

SupunSam's avatar

I am using Sweet Alerts with my app. :

Alert::toast('Jobs Exported into Excel', 'info');

This is just a flash message.

Please or to participate in this conversation.