Skip to content

Commit

Permalink
Merge pull request #1 from novius/feature/add-publication-status-action
Browse files Browse the repository at this point in the history
add publication status action
  • Loading branch information
felixgilles authored Oct 13, 2023
2 parents 1054575 + 248bd09 commit 1ea0923
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class Post extends Resource
}
```

You can use the UpdatePlucationStatus action to mass update the publication status of your models.

```php
public function actions(Request $request): array
{
return [
UpdatePublicationStatus::make(),
];
}
```
## Lang files

If you want to customize the lang files, you can publish them with:
Expand Down
46 changes: 46 additions & 0 deletions src/Nova/Actions/UpdatePublicationStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Novius\LaravelNovaPublishable\Nova\Actions;

use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Http\Requests\NovaRequest;
use Novius\LaravelPublishable\Enums\PublicationStatus;

class UpdatePublicationStatus extends Action
{

/**
* Perform the action on the given models.
*
* @param \Laravel\Nova\Fields\ActionFields $fields
* @param \Illuminate\Support\Collection $models
* @return mixed
*/
public function handle(ActionFields $fields, Collection $models): void
{
foreach ($models as $model) {
$model->publication_status = $fields->publication_status;
$model->save();
}
}

/**
* Get the fields available on the action.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [
Select::make('Statut', 'publication_status')
->options([
PublicationStatus::published->value => trans('laravel-nova-publishable::messages.filters.published'),
PublicationStatus::unpublished->value => trans('laravel-nova-publishable::messages.filters.not_published'),
]),
];
}
}

0 comments on commit 1ea0923

Please sign in to comment.