[4.1][Feature] Custom error message in case destroy() failed
See original GitHub issueRight now there’s just one default message in case the destroy()
method failed.
I’m using some nesting/relations and I want to prevent the user from deleting the resource in case it has some specific relations still defined.
From functional point of view, everything works ok. I’m overriding the destroy()
method in the CrudController, doing the checks and failing the destroy if there’s a problem. But right now, there’s no way to tell the user about the specifics of the problem.
My approach would be to rewrite said part of list.blade.php
slightly, to:
error: function(result) {
// Show an alert with the result
var notificationText = "{{ trans('backpack::crud.delete_confirmation_not_message') }}";
// Is there anything custom we'd like to tell the user?
if (result.responseJSON.text != undefined) {
notificationText = result.responseJSON.text;
}
new PNotify({
title: "{{ trans('backpack::crud.delete_confirmation_not_title') }}",
text: notificationText,
type: "warning"
});
}
And with this, we are free to throw 409 (or some other 4**/5** code, if applicable) in the destroy()
method with some text. (e.g. return response()->json(['text' => $error)], 409);
)
It shouldn’t be a breaking change.
I don’t know if something like this isn’t a part of some other plans/PRs, so forgive me for not being informed, if that’s the case 😃
Is it worth a PR?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9 (8 by maintainers)
Good news everyone! We’ll finally have this in 4.1 - if you’re interested please follow the PR here https://github.com/Laravel-Backpack/CRUD/pull/2393
Oups - the issue was that we’d want to customize that error message. Reopening it and marking as to-do for 4.0.