LoginController將重定向循環返回到登錄路由。Auth :: routes()重定向循環
的LoginController:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
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 = '/register';
/**
* Create a new controller instance.
*
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function username()
{
return 'username';
}
}
路線/ web.php:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Auth::routes();
Route::get('/home', '[email protected]')->name('home');
// Enums Route //
Route::get('/genderEnum', '[email protected]');
Route::get('/modelTypeEnum', '[email protected]');
Route::get('/classCodeEnum', '[email protected]');
Route::get('/statusEnum', '[email protected]');
Route::get('/titleEnum', '[email protected]');
// test routes //
Route::get('/test', '[email protected]');
RouteServiceProvider:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
// Route::middleware('web')
// ->namespace($this->namespace)
// ->group(base_path('routes/web.php'));
Route::group([
'middleware' => ['auth', 'web', 'guest'],
'namespace' => $this->namespace
],function(){
require base_path('routes/web.php');
});
// Route::group(array(
// 'middleware' => ['web', 'auth'],
// 'namespace' => $this->namespace,
// ), function ($router) {
// require base_path('routes/web.php');
// });
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
}
我認爲這個問題與我RouteServiceProvider做。我嘗試授權用戶,當我點擊其他auth路由時,我被重定向回登錄視圖,然後繼續進入302重定向循環到登錄GET路由。
我在我的用戶模型中犯了一個錯誤,因爲我創建了我自己的基礎模型。我在其中擴展強制我實現Auth \ Authenticatable和Auth \ CanResetPassword以使用auth :: routes()。我在實現一些記憶標記函數和getAuthIdentifierName和getAuthIdentifier方法時犯了一個錯誤,這導致了路由問題。也是我在使用Auth :: user()方法時總是得到空用戶的原因。然而,在確定你的答案後,我正確地使用我的枚舉,以及如何使用其他控制器。謝謝。 –