0
無論如何,如果我插入有效或無效的憑據,用戶總是重定向到RedirectIfAuthenticated中間件中定義的路由。我的問題:我如何將認證用戶重定向到不同於非認證用戶的路由?Laravel 5.3身份驗證:嘗試不起作用
RedirectIfAuthenticated(中間件):
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/');
}
return $next($request);
這是我的LoginController:
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
public function authenticate(Request $data){
if (Auth::attempt(['cnpj' => $data['cnpj'], 'password' => $data['password'] ])){
return redirect()->route('someroute');
}
else{
return redirect()->route('login');
}
路線:
Route::get('/', function() {
return view('welcome');
}) -> name('/');
Route::post('/register', 'Auth\[email protected]');
Route::get('/register', function() {
return view('auth.register');
});
Route::get('/login', function(){
return view('auth.login');
})->name('login');
Route::post('/login', 'Auth\[email protected]');