Redirect after sending reset password in Laravel 5.1?

How to set redirection path after sending reset password?

The ResetsPaswords property specifies this code:

switch ($response) {
    case Password::RESET_LINK_SENT:
       return redirect()->back()->with('status', trans($response));

    case Password::INVALID_USER:
       return redirect()->back()->withErrors(['email' => trans($response)]);
}

But I do not want to change the supplier files. Is there another way?

+4
source share
4 answers

As you can see in the description code, a successful result is redirected back to the same route:

redirect()->back()->with('status', trans($response));

Note the variable statusin the method with(). This sets a temporary session variable, which you can then use inside your view template, for example. notify the user that the letter has been successfully installed.

@if (session('status'))

// ... notification that the email has been sent

@else

// ... your original form for submitting an email address

@endif

, , , . . , , , .

+2

, protected $redirectTo = '/dashboard'; PasswordController.

, :

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;

class PasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;

    protected $redirectTo = '/dashboard';

    //The rest of the controller below this...

, /dashboard , .

docs.

+12

ResetsPasswords : getSendResetLinkEmailSuccessResponse getSendResetLinkEmailFailureResponse, reset, , reset .

A good reason for the change is that (as in my case) you want to return the user to the main login screen after sending the reset password.

To do this, simply modify App\Http\Controllers\Auth\PasswordControllerand override the function, for example:

protected function getSendResetLinkEmailSuccessResponse($response)
{
    return redirect()->route('login')->with('status', trans($response));
}
+1
source

You do not need to edit provider files. Just open /app/Http/Controllers/Auth/PasswordController.php and add the following line of code to the PasswordController class

    protected $redirectPath = '/DesiredUrl';

Tested on Laravel 5.1

0
source

Source: https://habr.com/ru/post/1609214/


All Articles