Skip to content

Commit a94d59f

Browse files
committed
Added bulk action export example to docs.
1 parent 062dee9 commit a94d59f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
88

99
- Added functionality to display BooleanColumn as Yes/No instead of icons.
1010
- Added ButtonGroupColumn for multiple LinkColumns in one group. Pretty much built in action buttons support.
11+
- Added bulk action export example to docs.
1112

1213
## [2.5.0] - 2022-05-03
1314

docs/examples/bulk-action-export.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Bulk Action Export
3+
weight: 3
4+
---
5+
6+
Here's an example on exporting your data from a bulk action using [Laravel Excel](https://laravel-excel.com):
7+
8+
```php
9+
use App\Exports\UsersExport;
10+
use Maatwebsite\Excel\Facades\Excel;
11+
12+
public function bulkActions(): array
13+
{
14+
return [
15+
'export' => 'Export',
16+
];
17+
}
18+
19+
public function export()
20+
{
21+
$users = $this->getSelected();
22+
23+
$this->clearSelected();
24+
25+
return Excel::download(new UsersExport($users), 'users.xlsx');
26+
}
27+
```
28+
29+
The `UsersExport` class is a simple example of how to export data from a bulk action:
30+
31+
```php
32+
<?php
33+
34+
namespace App\Exports;
35+
36+
use App\Models\User;
37+
use Maatwebsite\Excel\Concerns\FromCollection;
38+
39+
class UsersExport implements FromCollection
40+
{
41+
public $users;
42+
43+
public function __construct($users) {
44+
$this->users = $users;
45+
}
46+
47+
public function collection()
48+
{
49+
return User::whereIn('id', $this->users)->get();
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)