如果未注册用户并尝试访问需要身份验证的页面,我会将访问者重定向为使用Bolierplate Laravel AuthCode登录。
但是,当我检查错误日志时,我收到并出现错误。 (它可以在客户端正常运行,没有任何问题) 错误日志:
Illuminate\Auth\AuthenticationException: Unauthenticated. in /home/forge/xyz.com/vendor/laravel/framework/src/Illuminate/Auth/GuardHelpers.php:40 Stack trace: #0 /home/forge/xyz.com/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php(292): Illuminate\Auth\SessionGuard->authenticate() #1 /home/forge/xyz.com/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(57): Illuminate\Auth\AuthManager->__call('authenticate', Array) #2 /home/forge/xyz.com/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(41): Illuminate\Auth\Middleware\Authenticate->authenticate(Array) #3 /home/forge/xyz.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Auth\Middleware\Authenticate->handle(Object(Illuminate\Http\Request), Object(Closure)) #4 /home/forge/xyz.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) #5 /home/forge/xyz.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(67): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) #6 /home/forge/xyz.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure)) #7 /home/forge/xyz.com/
代码:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/login';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function logout()
{
$this->guard()->logout();
return redirect()->route('login');
}
}
答案 0 :(得分:1)
您的异常处理程序( app / Exceptions / Handler.php )中有一个名为$dontReport
的属性,其中包含不报告的异常列表。
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
只需将异常类添加到数组。
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class
];