Auth 在 Laravel Tinker 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48427179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auth not working in Laravel Tinker
提问by ajon
From within Tinker I am trying to:
从 Tinker 内部,我试图:
>>> Auth::loginUsingId(12);
=> false
>>> Auth::user();
=> null
>>> Auth::attempt(['email' => '[email protected]']);
=> false
I am guessing that since Auth typically uses session data, and maybe sessions don't work with tinker.
我猜是因为 Auth 通常使用会话数据,并且会话可能不适用于 tinker。
Is it possible to authenticate within tinker?
是否可以在 tinker 中进行身份验证?
回答by Alexey Mezenin
It's possible to login in Tinker. For example:
可以在 Tinker 中登录。例如:
auth()->loginUsingId(1)
auth()->id()
Normally, the output of the auth()->id()
will be 1
.
通常,输出auth()->id()
将是1
.
If it doesn't work for you, make sure the storage
directory is writable:
如果它不适合您,请确保该storage
目录可写:
sudo chmod -R 755 storage
You're also doing it wrong when you're using the attempt()
method. The correct syntax is:
当您使用该attempt()
方法时,您也做错了。正确的语法是:
attempt(['email' => '[email protected]', 'password' => 'secret'])