gpt4 book ai didi

laravel - 如何使用 Sentinel 执行 actingAs()

转载 作者:行者123 更新时间:2023-11-28 21:27:11 25 4
gpt4 key购买 nike

我正在测试需要用户登录的 Laravel 5.1 页面。我的项目使用 Cartalyst/Sentinel 包进行身份验证。

我试过了,但我无法识别用户是否已登录。

public function testPageWithLogin()
{
$user = Sentinel::findById(2);

$this->actingAs($user)
->withSession([])
->visit('/page')
->dontSee('Whoops')
->dontSee('login');
}

我该怎么做才能让用户被视为已登录?

最佳答案

我忘记使用 Sentinel::login 方法登录用户。用户是合法的,只是未被视为已登录。

这是应该的方式。

public function testPageWithLogin()
{
$user = Sentinel::findById(2);
Sentinel::login($user);

$this->actingAs($user)
->withSession([])
->visit('/page')
->dontSee('Whoops')
->dontSee('login');
}

关于laravel - 如何使用 Sentinel 执行 actingAs(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37085017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com