Skip to content

Commit 45317c0

Browse files
authored
Merge pull request #16415 from snipe/nicer_error_message_on_model_not_found
Nicer model name formatting on RMB model not found
2 parents 16b97c1 + 63e4c42 commit 45317c0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

app/Exceptions/Handler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ public function render($request, Throwable $e)
125125
// This is traaaaash but it handles models that are not found while using route model binding :(
126126
// The only alternative is to set that at *each* route, which is crazypants
127127
if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
128-
$model_name = last(explode('\\', $e->getModel()));
128+
129+
// This gets the MVC model name from the exception and formats in a way that's less fugly
130+
$model_name = strtolower(implode(" ", preg_split('/(?=[A-Z])/', last(explode('\\', $e->getModel())))));
129131
$route = str_plural(strtolower(last(explode('\\', $e->getModel())))).'.index';
130132

131133
// Sigh.

0 commit comments

Comments
 (0)