From 777e1d15d6eca0501e2f499f75d1ba0ea157b823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Wed, 17 Mar 2021 12:22:05 +0300 Subject: [PATCH] Missing model record show message and redirect index page.. --- app/Exceptions/Handler.php | 15 +++++++++++++-- resources/lang/en-GB/errors.php | 19 ++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index ccabc4437..c5cc5e0c7 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -100,8 +100,19 @@ class Handler extends ExceptionHandler return response()->json(['error' => 'Not Found'], 404); } - // normal 404 view page feedback - return response()->view('errors.404', [], 404); + try { + $names = explode('.', $request->route()->getName()); + $names[count($names) - 1] = 'index'; + + $route = route(implode('.', $names)); + + flash(trans('errors.message.record'))->warning()->important(); + + return redirect($route); + } catch (\Exception $e) { + // normal 404 view page feedback + return response()->view('errors.404', [], 404); + } } if ($exception instanceof FatalThrowableError) { diff --git a/resources/lang/en-GB/errors.php b/resources/lang/en-GB/errors.php index c72a47530..e1e43b223 100644 --- a/resources/lang/en-GB/errors.php +++ b/resources/lang/en-GB/errors.php @@ -3,21 +3,22 @@ return [ 'title' => [ - '403' => 'Oops! Forbidden Access', - '404' => 'Oops! Page not found', - '500' => 'Oops! Something went wrong', + '403' => 'Oops! Forbidden Access', + '404' => 'Oops! Page not found', + '500' => 'Oops! Something went wrong', ], 'header' => [ - '403' => '403 Forbidden', - '404' => '404 Not Found', - '500' => '500 Internal Server Error', + '403' => '403 Forbidden', + '404' => '404 Not Found', + '500' => '500 Internal Server Error', ], 'message' => [ - '403' => 'You can not access this page.', - '404' => 'We could not find the page you were looking for.', - '500' => 'We will work on fixing that right away.', + '403' => 'You can not access this page.', + '404' => 'We could not find the page you were looking for.', + '500' => 'We will work on fixing that right away.', + 'record' => 'We could not find the record you were looking for.', ], ];