【问题标题】:How to upgrade App\Exceptions from laravel 7 to laravel 8如何将 App\Exceptions 从 laravel 7 升级到 laravel 8
【发布时间】:2021-10-09 20:24:08
【问题描述】:
如何升级 App\Exceptions;从 laravel 7 到 laravel 8
public function render($request, Throwable $exception)
{
if ($exception instanceof UnauthorizedException) {
if (Auth::user() instanceof Admin) {
return redirect()->route('dashboard');
}
return redirect()->route('home');
}
return parent::render($request, $exception);
}
【问题讨论】:
标签:
php
laravel
laravel-8
laravel-7
【解决方案1】:
请更改您的app/Exceptions/Handler.php,如下所示
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}
}