我对Laravel并不陌生,并且对“记住我”功能有疑问。
通过将第二个参数附加到Auth :: attempt方法中,我已经成功启用了“记住我”功能。
if (Auth::attempt(array('email' => $email, 'password' => $password), true))
{
// The user is being remembered...
}
如文档中所述,这使您可以无限期记住我,或者直到用户手动注销为止。
我本质上是想在“记住我”功能上设置过期日期。
查看控制台,可以看到启用“记住我”会生成一个Remember_ {HASH} cookie。
覆盖此Cookie中指定的过期日期以使其成为未来一周的最佳方法是什么? Cookie当前会设置过去的日期,从而使它永远存在。
请记住,我必须在sessions.php中设置“ lifetime” => 0,以便我可以根据用户偏好触发“记住我”功能,因此在我的情况下将其更改为一周是不可行的。
谢谢!
参考方案
我不知道这是否是一个好方法,但是,如果您急于为记住的时间设置到期时间,可以尝试一下,但这对我有用。
让laravel的Auth::atempt($credential,true)
正常工作,即将“记住我”的有效期设置为5年
我们将在App::after()
方法中对此进行更改,因此在您的filters.php
文件中找到App::after()
方法并更改cookie的过期时间
App::after(function($request, $response)
{
if ( Auth::check()){
$ckname=Auth::getRecallerName(); //Get the name of the cookie, where remember me expiration time is stored
$ckval=Cookie::get($ckname); //Get the value of the cookie
return $response->withCookie(Cookie::make($ckname,$ckval,360)); //change the expiration time
}
});
注意:Cookie::make('name','value','expiration time');
我正在编写一些Laravel Blade模板,并且我的模型可能包含空对象。我非常想尝试获取对象属性,如果有错误,则返回null。因此,不必编写以下代码:@if ($model->child_object_that_may_be_null) {{ $model->child_object_that_may_be_null->interesti…
将所有具有特定路径名的URL重定向到某个视图-LARAVEL - php好的,我正在使用laravel,网站和管理版块运行两个React项目。我希望两个应用程序都在单独的页面上呈现,因为它们的CSS会发生冲突。因此,在我的web.php中,我有这个Route::view('/{path?}', 'app');,但这会将我的所有路线重定向到我的app.blade.php视图。我只是想知道我是…
Laravel-无需登录即可认证用户 - php在laravel 5.4中,可以在不登录用户的情况下对用户进行身份验证吗?从laravel doc中,我能找到的最接近的东西是:Auth::once($credentials) 但这仍然使该用户感到厌烦。我需要做的就是只是知道使用该电子邮件和密码的用户是否存在。 参考方案 您可以将Auth::attempt函数与第三个参数用作false进行登录 $email…
Laravel WHERE查询单列结果 - php我有以下控制器,应该返回所有尚未验证的用户。public function getUserRequests() { $userRequests = User::where('status' ,"Not Verified"); foreach($userRequests as $user) { echo $user-&g…
Laravel 5错误报告抑制 - php在Laravel 4中,抑制E_NOTICE消息很容易;我似乎无法做到这一点,因为如果我添加error_reporting(E_ALL ^ E_NOTICE) 它只是被覆盖的任何地方。这似乎发生在这里:(index.php)$response = $kernel->handle( $request = Illuminate\Http\Request::…