众所周知,Laravel 5.2 几天前发布了。我正在尝试这个新版本。我在 CLI 上使用以下命令创建了一个新项目:
laravel new testapp
根据Authentication Quickstart 的文档,我按照以下命令搭建路由和身份验证视图:
php artisan make:auth
它工作得很好。注册工作正常。但我在登录时遇到问题。登录后,我在 route.php 文件中测试了以下内容:
Route::get('/', function () {
dd( Auth::user());
return view('welcome');
});
Auth::user()
正在返回null
,Auth::check()
并且Auth::guest()
工作不正常。我通过制作新项目一次又一次地尝试了两三次,但无法获得正确的结果。
下面是完整的route.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.
|
*/
Route::get('/', function () {
dd( Auth::());
return view('welcome');
});
/*
|--------------------------------------------------------------------------
| 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('/home', 'HomeController@index');
});
谁能帮我?或者有人面临同样的问题吗?我该如何解决?