Handler.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Exceptions;
  3. use Auth;
  4. use Exception;
  5. use Illuminate\Session\TokenMismatchException;
  6. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  7. use Throwable;
  8. class Handler extends ExceptionHandler
  9. {
  10. /**
  11. * A list of the exception types that are not reported.
  12. *
  13. * @var array
  14. */
  15. protected $dontReport = [
  16. //
  17. ];
  18. /**
  19. * A list of the inputs that are never flashed for validation exceptions.
  20. *
  21. * @var array
  22. */
  23. protected $dontFlash = [
  24. 'password',
  25. 'password_confirmation',
  26. ];
  27. /**
  28. * Report or log an exception.
  29. *
  30. * @param \Throwable $exception
  31. * @return void
  32. *
  33. * @throws \Exception
  34. */
  35. public function report(Throwable $exception)
  36. {
  37. parent::report($exception);
  38. }
  39. /**
  40. * Render an exception into an HTTP response.
  41. *
  42. * @param \Illuminate\Http\Request $request
  43. * @param \Throwable $exception
  44. * @return \Symfony\Component\HttpFoundation\Response
  45. *
  46. * @throws \Throwable
  47. */
  48. public function render($request, Throwable $exception)
  49. {
  50. if ($this->isHttpException($exception)) {
  51. if($request->segment(1) == 'admin'){
  52. if (view()->exists('admin.errors.' . $exception->getStatusCode())) {
  53. return response()->view('admin.errors.' . $exception->getStatusCode(), [], $exception->getStatusCode());
  54. }
  55. }else{
  56. if (view()->exists('errors.' . $exception->getStatusCode())) {
  57. return response()->view('errors.' . $exception->getStatusCode(), [], $exception->getStatusCode());
  58. }
  59. }
  60. }
  61. if ($exception instanceof TokenMismatchException) {
  62. if($request->segment(1) == 'admin'){
  63. Auth::guard('admin')->logout();
  64. return redirect(route('admin.login'))->with('error', 'Page session expired. Please try again');
  65. }
  66. }
  67. return parent::render($request, $exception);
  68. }
  69. }