mercredi 6 septembre 2017

Handling Laravel TokenMismatchExceptions with error message

I modified function Exceptions/Handler.php->render. So now I have

public function render($request, Exception $exception)
    {
        if ($exception instanceof \Illuminate\Session\TokenMismatchException){
            return redirect()->back()->withInput($request->except('_token'))->withErrors('Your session has expired. Please log in again.');
        }
        return parent::render($request, $exception);
    }

I log into application and open form, but before submit form I delete all cookies (in order to force 'TokenMismatchException') and click submit button. Next thing occurs: I'm on login page again, but there no way to get error message (I tried lot of different combinations with "->with" and session and what not). After I login again I'm at my form but form is empty now. Anyone? Looks like is impossible to create session error from Handler.php.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire