Search code examples
laravelpasswordslaravel-authentication

Laravel Authentication Reset


I'm having difficulty how do I get the user id based on the token generated by laravel? I'm not very familiar with framewrok can anyone help me?

class ForgotPasswordController extends Controller
{
    use SendsPasswordResetEmails;

    /**
    * Create a new controller instance.
    *
    * @return void
    */
    public function __construct()
    {
        $this->middleware('guest');
    }
}

ResetPasswordController

class ResetPasswordController extends Controller
{

    use ResetsPasswords;

    protected $redirectTo = '/login';

    public function __construct()
    {

        $this->middleware('guest');
    }

    protected function guard()
    {
        return Auth::guard('user');
    }

    public function broker()
    {
        return Password::broker('users');
    }

    public function showResetForm(Request $request, $token = null)
    {
        var_dump($request->email);
        var_dump( $request->token);

        return view('auth.passwords.reset')->with(
            ['token' => $token, 'email' => $request->email]
        );
    }
}

how to update password? I only have the token received by email?


Solution

  • Check this steps so you can understand better how laravel auth works.

    1. Generate the auth scaffolding with: php artisan make:auth
    2. Run the created migrations:php artisan migrate
    3. Check your route list with php artisan route:list, you can see that routes were created too when you ran make:auth command.
    4. Take note of the controllers and methods the Auth routes are calling.
    5. Go to the routes web.php file. See the Auth::routes();, this generate the default Laravel Auth routes, if you don't need em all, comment or delete this line and add the required Lines.
    6. If you took note of the controllers and methods, you can see what's been called on each route. In this particular case, i think you'd be looking for ResetPasswordController which uses ResetsPasswords from vendor/laravel/framework/src/Illuminate/Foundation/Auth/ResetsPasswords.php there you can see the resets method this is what you'll have to override on your ResetPasswordController.