forked from livewire/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-downloads.blade.php
40 lines (35 loc) · 972 Bytes
/
file-downloads.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Livewire supports triggering file downloads for users with a simple, intuitive API.
To trigger a file download, you can return a Laravel file download from any component action.
@component('components.code-component')
@slot('class')
@verbatim
class ExportButton extends Component
{
public function export()
{
return Storage::disk('exports')->download('export.csv');
}
}
@endverbatim
@endslot
@slot('view')
@verbatim
<button wire:click="export">
Download File
</button>
@endverbatim
@endslot
@endcomponent
Livewire should handle any file download that Laravel would. Here are a few other utilities you might use:
@component('components.code', ['lang' => 'php'])
@verbatim
return response()->download(storage_path('exports/export.csv'));
@endverbatim
@endcomponent
@component('components.code', ['lang' => 'php'])
@verbatim
return response()->streamDownload(function () {
echo 'CSV Contents...';
}, 'export.csv');
@endverbatim
@endcomponent