相关疑难解决方法(0)

Laravel 5.2 Auth无法正常工作

你们知道Laravel 5.2几天前发布了.我正在尝试这个新版本.我在CLI上使用以下命令创建了一个新项目:

laravel new testapp
Run Code Online (Sandbox Code Playgroud)

根据Authentication Quickstart的文档,我按照以下命令来构建身份验证的路由和视图:

php artisan make:auth
Run Code Online (Sandbox Code Playgroud)

它工作正常.注册工作正常.但我在登录时遇到问题.登录后我在route.php文件中测试了以下内容:

   Route::get('/', function () {
    dd( Auth::user());
    return view('welcome');
});
Run Code Online (Sandbox Code Playgroud)

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. …
Run Code Online (Sandbox Code Playgroud)

php authentication laravel laravel-5 laravel-5.2

18
推荐指数
1
解决办法
2万
查看次数

Auth :: user()在Laravel 5.2中返回null

我搜索并找到了各种类似的结果: 在Laravel 5.2中auth() - > user()为null , Auth :: user()返回null

但是,我的仍然没有工作.

Auth::user()适用于控制器,但不适用于模型.它回来了null.

代码是:

public function scopeOwned($query) {
    $query->where('user_id', '=', Auth::user()->id);
}
Run Code Online (Sandbox Code Playgroud)

我试过了dd(Auth::user()),它也回来null了.

任何的想法?

laravel laravel-5 laravel-5.2

3
推荐指数
1
解决办法
2808
查看次数

标签 统计

laravel ×2

laravel-5 ×2

laravel-5.2 ×2

authentication ×1

php ×1