Laravel Nova资源删除后无法显示自定义成功消息的问题求助
Laravel Nova资源删除后无法显示自定义成功消息的问题求助
我在Laravel Nova的ContactUs资源中,尝试通过afterDelete钩子返回自定义删除成功提示,但执行删除操作后完全看不到设置的"Contact Us entry deleted successfully."消息。更奇怪的是,就算我移除整个afterDelete方法,Nova也不会显示默认的删除确认消息。有没有朋友能帮忙排查下问题所在?
以下是我的ContactUs资源完整代码:
<?php namespace App\Nova; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Laravel\Nova\Actions\Action; use Laravel\Nova\Fields\ID; use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Fields\Text; use Laravel\Nova\Fields\DateTime; use Laravel\Nova\Actions\ActionResponse; class ContactUs extends Resource { /** * The model the resource corresponds to. * * @var class-string<\App\Models\ContactUs> */ public static $model = \App\Models\ContactUs::class; /** * The single value that should be used to represent the resource when being displayed. * * @var string */ public function title() { return $this->first_name . ' ' . $this->last_name; } /** * Get the searchable columns for the resource. * * @return array */ public static function searchableColumns() { return ['id', DB::raw("CONCAT(first_name, ' ', last_name)"), 'email', 'phone_no']; } public static function authorizedToCreate(Request $request) { return false; } public function authorizedToUpdate(Request $request): bool { return false; } public function authorizedToDelete(Request $request): bool { return true; } public function authorizedToReplicate(Request $request): bool { return false; } // Hook into the deletion process public static function afterDelete(Request $request, $model) { return ActionResponse::message('Contact Us entry deleted successfully.'); } /** * Get the fields displayed by the resource. * * @return array<int, \Laravel\Nova\Fields\Field> */ public function fields(NovaRequest $request): array { return [ Text::make('First Name')->rules('required'), Text::make('Last name')->rules('required'), Text::make('Email')->rules('required'), Text::make('Message', function () { return $this->message ?: '<em>No message provided.</em>'; })->asHtml()->onlyOnDetail(), DateTime::make('Created At') ->readonly(), ]; } public static function label() { return 'Contact Us'; } public static function singularLabel() { return 'Contact Us'; } /** * Get the cards available for the resource. * * @return array<int, \Laravel\Nova\Card> */ public function cards(NovaRequest $request): array { return []; } /** * Get the filters available for the resource. * * @return array<int, \Laravel\Nova\Filters\Filter> */ public function filters(NovaRequest $request): array { return []; } /** * Get the lenses available for the resource. * * @return array<int, \Laravel\Nova\Lenses\Lens> */ public function lenses(NovaRequest $request): array { return []; } /** * Get the actions available for the resource. * * @return array<int, \Laravel\Nova\Actions\Action> */ public function actions(NovaRequest $request): array { return []; } }
我已经确认删除操作能正常执行,数据库里的记录确实被删掉了,就是没有任何提示消息。试过清除缓存、重新登录Nova,问题依然存在。有没有人遇到过类似的情况?或者能指出我代码里的错误?




