Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hendrik_eka's avatar

Override the resetPassword

I have a problem with changing the password in laravel. I have 2 tables of users in the database, the first table is a Users, and the second is Mahasiswas. I'm using the first table which is Users to work as an admin, and the second table Mahasiswas which means students in my language to enter study program card.

The both tables can login smoothly, but when I try to change the password of the student from the table Mahasiswas, the system begins automatically logged in to the User Dashboard (and it is very dangerous for Users), not to Mahasiswas Dashboard, and I do not want the system to log in automatically after changing the password, so how can I override the resetPassword.php trait ?

0 likes
2 replies
Snapey's avatar

You will need to write your own controller, and implement your own methods. You can easily read the existing traits to give you an idea.

hendrik_eka's avatar

@Snapey

I put this in my route :

Route::post('password/reset', 'MhsAuth\PasswordController@postMyReset');

And this is my passwordController :

namespace App\Http\Controllers\MhsAuth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{

        use ResetsPasswords;
    protected $redirectPath = '/';
        protected $getGuard = 'mahasiswa';

    public function __construct()
        {
            $this->middleware('mahasiswa');
        }

        public function postMyReset(Request $request)
        {
            return $this->resetMe($request);
        }

    public function resetMe(Request $request)
        {
            $this->validate($request, [
                    'token' => 'required',
                    'email' => 'required|email',
                'password' => 'required|confirmed|min:6',
            ]);

            $credentials = $request->only(
                    'email', 'password', 'password_confirmation', 'token'
            );

            $broker = $this->getBroker();

            $response = Password::broker($broker)->reset($credentials, function ($user, $password) {
                    $this->resetMyPassword($user, $password);
            });

            switch ($response) {
                    case Password::PASSWORD_RESET:
                        return $this->getResetSuccessResponse($response);

                    default:
                        return $this->getResetFailureResponse($request, $response);
            }
    }

        protected function resetMyPassword($user, $password)
    {
            $user->password = bcrypt($password);
            $user->save();
            //Auth::guard($this->getGuard())->login($user);
        }

}

The problem is after reset the password for Mahasiswas table, it's perform auto login to Users Dashboard, it should be in Mahasiswas Dashboard, but I just want to disable the autologin and my passwordController doesn't work as I wanted. Thanks

Please or to participate in this conversation.