我正在使用Laravel 5.2和Laravel Authentication开箱即用。 这是我的步骤: 1)安装laravel 2)php artisan migrate 3)php artisan make:auth
一切都准备好了,至少应该是......
比我打开localhost / project / public
a)按注册链接,注册新帐户,如果成功,它会重定向到/ home并告诉我已登录并显示我的用户名。 b)但是一旦我点击另一个链接(例如重定向到/的主页按钮),用户就不再登录了。而且由于我没有登录,我可以看到登录和注册链接,但是它们被重定向到/如预期的那样。
我提到如果我在AuthController中评论这一行(即使我已登录也允许访问登录页面)
public function __construct()
{
//$this->middleware('guest', ['except' => 'logout']);
}
在步骤b)之后使用此注释行我按下登录或注册链接并且...用户再次登录..非常奇怪的行为。 如果我打开http://localhost/project/public/home,它表示我已登录。
来自routes.php文件的代码:
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController@index'); });
有谁知道如何解决这个问题?
答案 0 :(得分:2)
基本上,这就是我的routes.php文件的样子,它完美地运行:
<?php
/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
//
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/', function () {
return view('welcome');
});
Route::get('/home', 'HomeController@index');
});