[英]Logout and redirect user back to login blade with a message on change password in laravel
I'm trying to logout and redirect my user back to login blade once the user's password is changed successfully.一旦用户的密码成功更改,我正在尝试注销并将我的用户重定向回登录刀片。
This is my controller so far (only the function is included),到目前为止,这是我的控制器(仅包含该功能),
public function store(Request $request)
{
$request->validate([
'current_password' => ['required', new MatchOldPassword],
'new_password' => ['required', 'string', 'min:12', 'confirmed','regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,}$/'],
'new_confirm_password' => ['same:new_password'],
]);
User::find(auth()->user()->id)->update(['password'=> Hash::make($request->new_password)]);
//dd('Password change successfully.');
}
Here on success how can I logout and redirect my user back to login blade with a success message (Pass word has been changed. Please log in again)这里成功了,我如何注销并将我的用户重定向回登录刀片并显示成功消息(密码已更改。请重新登录)
I have two solution to this problem.我有两个解决这个问题的方法。 Simply add with
function to create a flash message you wanted.只需添加with
函数来创建你想要一个提示信息。
AuthenticatesUsers.php
and inside the logout
function change the redirected route from /
to /login
.
解决方案 1:转到AuthenticatesUsers.php
并在logout
函数中将重定向的路由从/
更改为/login
。
(Assuming your using make:auth
)
(假设您使用make:auth
)
public function logout(Request $request) { //more codes here return $request->wantsJson() ? new Response('', 204) : redirect('/login')->with('success', 'Password change successfully.'); }
public function logout() { \\Auth::logout(); return redirect('/login')->with('success', 'Password change successfully.'); }
我认为您可以重定向到您的注销功能并将会话消息返回到登录刀片。
Auth::logout();认证::登出(); return redirect('/login');返回重定向('/登录');
For showing a message you can use用于显示您可以使用的消息
https://github.com/CodeSeven/toastr https://github.com/CodeSeven/toastr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.