Show a success message after deletion from nova resource
*/
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
*/
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 ?: 'No message provided.';
})->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
*/
public function cards(NovaRequest $request): array
{
return [];
}
/**
* Get the filters available for the resource.
*
* @return array
*/
public function filters(NovaRequest $request): array
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @return array
*/
public function lenses(NovaRequest $request): array
{
return [];
}
/**
* Get the actions available for the resource.
*
* @return array
*/
public function actions(NovaRequest $request): array
{
return [];
}
}
I added an ActionResponse::message inside the afterDelete method of this resource. However, after deleting a record, the message “Contact Us entry deleted successfully.” does not appear. If I remove the afterDelete method entirely, no confirmation message is displayed by default. Can anyone help me regarding this issue?