laravelroutesparameterslaravel-8

Larvel - how to return view with token


Route::get('/password/reset/{token}', [PasswordResetController::class, 'showResetPasswordPage'])->name('password.reset.token');
   public function showResetPasswordPage(Request $request)
    {

        $token = $request->route()->parameter('token');

        return view('resetpassword')->with(
            ['token' => $token]
        );
    }

I have this as my route in web.php - if it pass the parameter as 1234 as the token reference, the view is returned and I can grab the token.

However, the API I'm using sends a reset code like this 'PKKGhoTq6Po3HzgpqThGyN1g8%2F%2BvPabz' which if I pass to the url - comes up as not found.

Is there a way to parse this so I can return the view with the token as it works when using 1234?

Any help would be appreciated.

Tried different parameters / route setups with no avail.


Solution

  • Seems that was the case - I added ->where('token', '.*'); to the end of the route in web.php and now the view is loading and token available.

    In web.php this is the route which was returning the view:

    Route::get('/password/reset/{resetCode}', [PasswordResetController::class, 'showResetPasswordPage'])->name('password.reset.resetCode')->where('resetCode', '.*');
    

    Controller:

        public function showResetPasswordPage(Request $request, string $resetCode)
    {
        return view('resetpassword')->with(
            ['token' => $resetCode]
        );
    }
    

    Adding ->where('resetCode', '.*'); to the end of the route stopped Larvel from filtering the token and passed it to the view without issue.