英文:
Laravel login - After the login is successful, it does not remain and returns to the login page
问题
以下是您要翻译的代码部分:
我尝试了几种登录方式,有效的是 `Auth::login($user);`,但他无法保持登录状态,而是回到登录页面。
登录控制器:
```php
public function validateCode(Request $request)
{
$email = $request->email;
// 获取用户
$user = User::where('email', $email)->first();
if ($user->count() > 0) {
$validateCode = $request->input('validateCode');
// 检查验证码
if ($validateCode == $user['codConfirm']) {
Auth::login($user, true);
if (Auth::check())
return redirect()->route('home');
else {
dd('else');
return redirect()->action('Auth\LoginController@index', ['validator' => ['无法登录']]);
}
} else {
return view('confirmar-usuario', ['email' => $email]);
}
} else {
flash('无效用户')->error();
return view('login');
}
}
英文:
I tried several ways to login, the one that works is Auth::login($user);
, but he doesn't stay logged in, he goes back to the login page.
Login Controller:
public function validateCode(Request $request)
{
$email = $request->email;
// Get user
$user = User::where('email', $email)->first();
if ($user->count() > 0) {
$validateCode = $request->input('validateCode');
// Check the codes
if ($validateCode == $user['codConfirm']) {
Auth::login($user, true);
if(Auth::check())
return redirect()->route('home');
else{
dd('else');
return redirect()->action('Auth\LoginController@index', ['validator' => ['Não foi possível fazer o login']]);
}
} else {
return view('confirmar-usuario', ['email' => $email]);
}
}
else {
flash('Usuário inválido')->error();
return view('login');
}
}
I will answer my own question as I found out and the question I had thought about has been deleted. So I'm posting here to help someone.
答案1
得分: 5
没问题,问题只在于 .env 文件。有两个重要的信息必须填写正确。'SESSION_DOMAIN' 和 'APP_URL'。
URL 必须没有协议和端口,如果有的话。
例如:
APP_URL=127.0.0.1
SESSION_DOMAIN=127.0.0.1
英文:
It's all right, the issue is only the .env. There are two important pieces of information that must be filled in correctly. 'SESSION_DOMAIN' and 'APP_URL'.
The url must be without the protocol and without the port, if any.
Ex:
APP_URL=127.0.0.1
SESSION_DOMAIN=127.0.0.1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论