PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

[FIXED] Confirm form resubmission Laravel

 February 01, 2022     authentication, laravel-5     No comments   

Issue

I am redirecting users based on their roles, I changed my AuthenticatedUsers.php and added this to the authenticated function

protected function authenticated(Request $request, $user)
{
    if (Auth::user()->priority == 'HI') {
        return view ('dashboard');
    }else{
        return view ('home');
    }
}

Now I got it working to redirect based on roles, however when I refresh the page FOR THE FIRST TIME it shows

CONFIRM FORM RESUBMISSION


Solution

You are not redirecting the user, you are only rendering a view.

use redirect to redirect the user:

protected function authenticated(Request $request, $user)
{
    if (Auth::user()->priority == 'HI') {
        return redirect('dashboard');
        // with named routes
        return redirect()->route('dashboard');
    } else {
        return redirect('home');
        // with named routes
        return redirect()->route('home');
    }
}


From the docs:

Creating Redirects:

Redirect responses are instances of the Illuminate\Http\RedirectResponse class, and contain the proper headers needed to redirect the user to another URL. There are several ways to generate a RedirectResponse instance. The simplest method is to use the global redirect helper:

Route::get('dashboard', function () {
    return redirect('home/dashboard');
});


Redirecting To Named Routes

When you call the redirect helper with no parameters, an instance of Illuminate\Routing\Redirector is returned, allowing you to call any method on the Redirector instance. For example, to generate a RedirectResponse to a named route, you may use the route method:

return redirect()->route('login');


Answered By - Remul
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing