From 233f4fd19a4ebd065de9e1f0d9dc6d703acf6c94 Mon Sep 17 00:00:00 2001 From: drewroberts Date: Fri, 18 Sep 2020 17:09:26 -0400 Subject: [PATCH] Use new slug field in Laravel Nova #9 --- composer.json | 2 +- src/Nova/Post.php | 13 ++++++------- src/Nova/Series.php | 15 +++++++-------- src/Nova/Topic.php | 15 +++++++-------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index d602b64..13aab2d 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^7.3", - "benjaminhirsch/nova-slug-field": "^1.2", + "laravel/nova": "^3.10.0", "drewroberts/media": "^1.0" }, "require-dev": { diff --git a/src/Nova/Post.php b/src/Nova/Post.php index d8e4440..51c7536 100644 --- a/src/Nova/Post.php +++ b/src/Nova/Post.php @@ -2,13 +2,12 @@ namespace DrewRoberts\Blog\Nova; -use Benjaminhirsch\NovaSlugField\Slug; -use Benjaminhirsch\NovaSlugField\TextWithSlug; use Illuminate\Http\Request; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\DateTime; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Markdown; +use Laravel\Nova\Fields\Slug; use Laravel\Nova\Fields\Text; use Laravel\Nova\Fields\Textarea; use Laravel\Nova\Http\Requests\NovaRequest; @@ -43,8 +42,8 @@ public function fieldsForIndex(NovaRequest $request) public function fields(Request $request) { return [ - TextWithSlug::make('Title')->slug('slug'), - Slug::make('Slug')->disableAutoUpdateWhenUpdating(), + Text::make('Title')->required(), + Slug::make('Slug')->from('Title'), DateTime::make('Published', 'published_at'), BelongsTo::make('Series'), BelongsTo::make('Author', 'author', 'App\Nova\User')->nullable(), @@ -72,9 +71,9 @@ protected function dataFields() { return [ ID::make(), - DateTime::make('Created At')->hideWhenCreating()->hideWhenUpdating(), - BelongsTo::make('Updated By', 'updater', 'App\Nova\User')->hideWhenCreating()->hideWhenUpdating(), - DateTime::make('Updated At')->hideWhenCreating()->hideWhenUpdating(), + DateTime::make('Created At')->exceptOnForms(), + BelongsTo::make('Updated By', 'updater', 'App\Nova\User')->exceptOnForms(), + DateTime::make('Updated At')->exceptOnForms(), ]; } diff --git a/src/Nova/Series.php b/src/Nova/Series.php index a956a15..cd5a76f 100644 --- a/src/Nova/Series.php +++ b/src/Nova/Series.php @@ -2,14 +2,13 @@ namespace DrewRoberts\Blog\Nova; -use Benjaminhirsch\NovaSlugField\Slug; -use Benjaminhirsch\NovaSlugField\TextWithSlug; use Illuminate\Http\Request; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\DateTime; use Laravel\Nova\Fields\HasMany; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Markdown; +use Laravel\Nova\Fields\Slug; use Laravel\Nova\Fields\Text; use Laravel\Nova\Fields\Textarea; use Laravel\Nova\Http\Requests\NovaRequest; @@ -43,8 +42,8 @@ public function fieldsForIndex(NovaRequest $request) public function fields(Request $request) { return [ - TextWithSlug::make('Title')->slug('slug'), - Slug::make('Slug')->disableAutoUpdateWhenUpdating(), + Text::make('Title')->required(), + Slug::make('Slug')->from('Title'), BelongsTo::make('Topic'), Textarea::make('Note')->nullable(), @@ -74,10 +73,10 @@ protected function dataFields() { return [ ID::make(), - BelongsTo::make('Created By', 'updater', 'App\Nova\User')->hideWhenCreating()->hideWhenUpdating(), - DateTime::make('Created At')->hideWhenCreating()->hideWhenUpdating(), - BelongsTo::make('Updated By', 'updater', 'App\Nova\User')->hideWhenCreating()->hideWhenUpdating(), - DateTime::make('Updated At')->hideWhenCreating()->hideWhenUpdating(), + BelongsTo::make('Created By', 'updater', 'App\Nova\User')->exceptOnForms(), + DateTime::make('Created At')->exceptOnForms(), + BelongsTo::make('Updated By', 'updater', 'App\Nova\User')->exceptOnForms(), + DateTime::make('Updated At')->exceptOnForms(), ]; } diff --git a/src/Nova/Topic.php b/src/Nova/Topic.php index abd04cd..2eabe89 100644 --- a/src/Nova/Topic.php +++ b/src/Nova/Topic.php @@ -2,14 +2,13 @@ namespace DrewRoberts\Blog\Nova; -use Benjaminhirsch\NovaSlugField\Slug; -use Benjaminhirsch\NovaSlugField\TextWithSlug; use Illuminate\Http\Request; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\DateTime; use Laravel\Nova\Fields\HasMany; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Markdown; +use Laravel\Nova\Fields\Slug; use Laravel\Nova\Fields\Text; use Laravel\Nova\Fields\Textarea; use Laravel\Nova\Http\Requests\NovaRequest; @@ -43,8 +42,8 @@ public function fieldsForIndex(NovaRequest $request) public function fields(Request $request) { return [ - TextWithSlug::make('Title')->slug('slug'), - Slug::make('Slug')->disableAutoUpdateWhenUpdating(), + Text::make('Title')->required(), + Slug::make('Slug')->from('Title'), Textarea::make('Note')->nullable(), new Panel('Content Fields', $this->contentFields()), @@ -74,10 +73,10 @@ protected function dataFields() { return [ ID::make(), - BelongsTo::make('Created By', 'updater', 'App\Nova\User')->hideWhenCreating()->hideWhenUpdating(), - DateTime::make('Created At')->hideWhenCreating()->hideWhenUpdating(), - BelongsTo::make('Updated By', 'updater', 'App\Nova\User')->hideWhenCreating()->hideWhenUpdating(), - DateTime::make('Updated At')->hideWhenCreating()->hideWhenUpdating(), + BelongsTo::make('Created By', 'updater', 'App\Nova\User')->exceptOnForms(), + DateTime::make('Created At')->exceptOnForms(), + BelongsTo::make('Updated By', 'updater', 'App\Nova\User')->exceptOnForms(), + DateTime::make('Updated At')->exceptOnForms(), ]; }