Skip to content

Commit f730fcb

Browse files
committed
Added new sctio stub for bulk actions and changed documentation
1 parent f8a37b5 commit f730fcb

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

doc/table-view.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This view creates a dynamic data table with some features like filters, paginati
2121
- [Changing title](#changing-title)
2222
- [Actions](#actions)
2323
- [Registering actions](#registering-actions)
24+
- [Bulk actions](#bulk-actions)
2425
- [Redirect action](#redirect-action)
2526
- [Showing feedback messages](#showing-feedback-messages)
2627
- [Hiding actions](#hiding-actions)
@@ -317,6 +318,23 @@ protected function actionsByRow()
317318
}
318319
```
319320

321+
## Bulk actions
322+
You can execute bulk actions selecting items on the UI defining a `bulkActions` method with all the actions you want to use. If you define this method, a checkbox input will be displayed for each item to select or unselect it.
323+
324+
```php
325+
protected function bulkActions()
326+
{
327+
return [
328+
new ActivateUsersAction,
329+
];
330+
}
331+
```
332+
You can creat a bulk action by an artisan command just using the `--bulk` option.
333+
334+
```bash
335+
php artisan make:action Actions/ActivateUserAction --bulk
336+
```
337+
320338
## Redirect action
321339
This package has a defined action to redirect the user to a named route related to your model inside your project when the button is clicked, you can use it directly on the `actionsByRow` method
322340

@@ -395,7 +413,7 @@ public function getConfirmationMessage($item = null)
395413
```
396414

397415
# Showing UI components
398-
You can display some UI components instead of plain text like avateres, badges or icons, some of these components has different variants, you can customize these varians with the `laravel-views.php` config file.
416+
You can display some UI components instead of plain text like avaters, badges or icons, some of these components has different variants, you can customize these varians with the `laravel-views.php` config file.
399417

400418
## Avatar
401419
Shows an 32x32 rounded image

src/Console/ActionMakeCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ActionMakeCommand extends GeneratorCommand
1818
*
1919
* @var string
2020
*/
21-
protected $signature = 'make:action {name}';
21+
protected $signature = 'make:action {name} {--bulk}';
2222

2323
/**
2424
* The console command description.
@@ -34,6 +34,11 @@ class ActionMakeCommand extends GeneratorCommand
3434
*/
3535
protected function getStub()
3636
{
37+
$isBulk = $this->option('bulk');
38+
if ($isBulk) {
39+
return __DIR__ . "/../../stubs/bulk-action.stub";
40+
}
41+
3742
return __DIR__ . "/../../stubs/action.stub";
3843
}
3944

stubs/bulk-action.stub

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use LaravelViews\Actions\Action;
6+
use LaravelViews\Views\View;
7+
8+
class DummyClass extends Action
9+
{
10+
/**
11+
* Any title you want to be displayed
12+
* @var String
13+
* */
14+
public $title = "My action title";
15+
16+
/**
17+
* This should be a valid Feather icon string
18+
* @var String
19+
*/
20+
public $icon = "";
21+
22+
/**
23+
* Execute the action when the user clicked on the button
24+
*
25+
* @param Array $selectedModels Array with all the id of the selected models
26+
* @param $view Current view where the action was executed from
27+
*/
28+
public function handle($selectedModels, View $view)
29+
{
30+
// Your code here
31+
}
32+
}

0 commit comments

Comments
 (0)