Ad
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\[email protected]$!%*?&]{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)
Ad
Answer
I have two solution to this problem. Simply add with
function to create a flash message you wanted.
Solution 1: Go to the
AuthenticatesUsers.php
and inside the logout
function change the redirected route from /
to /login
. (Assuming your using make:auth
) public function logout(Request $request)
{
//more codes here
return $request->wantsJson()
? new Response('', 204)
: redirect('/login')->with('success', 'Password change successfully.');
}
Solution 2: Make a customed one. Create a controller function and add these following codes below:
public function logout()
{
\Auth::logout();
return redirect('/login')->with('success', 'Password change successfully.');
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad