Merge pull request #16415 from snipe/nicer_error_message_on_model_not_found

Nicer model name formatting on RMB model not found
This commit is contained in:
snipe 2025-03-04 19:42:45 +00:00 committed by GitHub
commit 45317c0959
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -125,7 +125,9 @@ class Handler extends ExceptionHandler
// This is traaaaash but it handles models that are not found while using route model binding :(
// The only alternative is to set that at *each* route, which is crazypants
if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
$model_name = last(explode('\\', $e->getModel()));
// This gets the MVC model name from the exception and formats in a way that's less fugly
$model_name = strtolower(implode(" ", preg_split('/(?=[A-Z])/', last(explode('\\', $e->getModel())))));
$route = str_plural(strtolower(last(explode('\\', $e->getModel())))).'.index';
// Sigh.