Laravel 5.2 身份验证不起作用
2022-08-30 22:08:03
如你们所知,Laravel 5.2几天前发布。我正在尝试这个新版本。我在CLI上使用以下命令制作了一个新项目:
laravel new testapp
根据身份验证快速入门的文档,我按照以下命令对身份验证的基架路由和视图进行了操作:
php artisan make:auth
它工作正常。注册工作正常。但我在登录中遇到了问题。登录后,我在路由.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');
});
任何人都可以帮我吗?或者是否有人面临同样的问题?我该如何修复它?