From 248bd092c66e1cea5593beb462e0a11494c821f7 Mon Sep 17 00:00:00 2001 From: RF Date: Fri, 13 Oct 2023 08:46:44 +0200 Subject: [PATCH] add publication status action --- README.md | 10 +++++ src/Nova/Actions/UpdatePublicationStatus.php | 46 ++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/Nova/Actions/UpdatePublicationStatus.php diff --git a/README.md b/README.md index 376f6ac..752d08e 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/Nova/Actions/UpdatePublicationStatus.php b/src/Nova/Actions/UpdatePublicationStatus.php new file mode 100644 index 0000000..60becd7 --- /dev/null +++ b/src/Nova/Actions/UpdatePublicationStatus.php @@ -0,0 +1,46 @@ +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'), + ]), + ]; + } +}