Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

J-Guo's avatar

What's the difference between redirect and return view()

Hi everyone,

I am a beginner in Laravel5. Can I ask a question about what is the difference between redirect and return view().In my controller, I have some codes to handle login. If authentication is passed, should I use redirect or return view(). For example,

if(!Auth::check())
    return redirect('login');
else
 //   return redirect('home') or return view('home');

Thank you for your help!

0 likes
4 replies
ifpingram's avatar

redirect() uses HTTP header redirects (301 etc.), whereas a view is a standard 200 response in the same request-response cycle.

I usually use views, and would only use redirects on things like failing authentication / page not allowed to be accessed etc.

3 likes
kfirba's avatar
kfirba
Best Answer
Level 50

@Eric-Guo hey.

The difference is that when you return a view you are responding to a uri. For example, when someone access the /about uri you respond by returning a view.

A redirect is actually changing the uri which means you actually invoke another controller's method. For example, when someone tries to login by accessing the page /login and the authentication fails, you want to redirect him back to the login page (note that submitting the login form will result in a post request and you don't want to return view from a post request as it only meant to process data).

Another example is when a user tries to access a uri such as /profile and he's not authenticated, you can't show him the profile, you want to show him the login form, but if you return the login form view, your uri will be /profile and you will display the login form, doesn't make sense and it will complicate your code so much. What you do in this example just redirect the user to the login page which results in a page refresh and actually hitting another route.

28 likes
J-Guo's avatar

Thank you very much with the detailed answers!

1 like

Please or to participate in this conversation.