Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel在测试中使用Auth:user()失败_Php_Laravel_Testing - Fatal编程技术网

Php Laravel在测试中使用Auth:user()失败

Php Laravel在测试中使用Auth:user()失败,php,laravel,testing,Php,Laravel,Testing,我有一个测试,我正试图在一个作用域数据库查询上运行,该查询只返回当前登录用户团队的结果。我遇到测试失败的问题,因为当使用actingAs进行测试时,Auth::user()似乎不起作用。这是我的测试: /** @test */ function a_team_has_ten_tickets() { $this->assertCount(10, $this->team_testing->tickets); } 作用域查询是: public function apply(

我有一个测试,我正试图在一个作用域数据库查询上运行,该查询只返回当前登录用户团队的结果。我遇到测试失败的问题,因为当使用actingAs进行测试时,Auth::user()似乎不起作用。这是我的测试:

/** @test */
function a_team_has_ten_tickets()
{
    $this->assertCount(10, $this->team_testing->tickets);
}
作用域查询是:

public function apply(Builder $builder, Model $model)
{
    return $builder->where('team_id', Auth::user()->current_team_id);
}
你知道为什么这不起作用,或者如何让它起作用吗


这里的原始问题:

出现了什么错误?
ErrorException:尝试获取引用行
return$builder->where('team\u id',Auth::user()->current\u team\u id)的非对象的属性出现了什么错误?
ErrorException:尝试获取引用行
return$builder->where('team\u id',Auth::user()->current\u team\u id)的非对象的属性