A free open source IT asset/license management system
Handle the not found errors with route model binding
snipe989082d719e5
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.phpindex 2b8eaa3627..80663b47ac 100644--- a/app/Exceptions/Handler.php+++ b/app/Exceptions/Handler.php@@ -122,6 +122,15 @@ 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()));+ $route_base = str_plural(strtolower(last(explode('\\', $e->getModel()))));+ return redirect()+ ->route($route_base.'.index')+ ->withError(trans('general.generic_model_not_found', ['model' => $model_name]));+ }if ($this->isHttpException($e) && (isset($statusCode)) && ($statusCode == '404' )) {