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

mac03733's avatar

return view('departments.index') VS return redirect()->route('departments.index')

is there any difference beside syntax , or does one have any side effects or recommenced use cases

0 likes
4 replies
manelgavalda's avatar

Yeah it has a difference:

  • In the first case you are just returning a view so you will get a HTTP status code of 200 (Successful).
  • In the second case you are redirecting the user to another route (that probably just returns the view), so you will get a HTTP status code of 302.

I suggest you to use the first case, because you are returning the view directly in your controller, in the other case your controller is redirecting to another route and hitting another controller that may do the same.

So it will be better to use the first case, it's less confusing and more direct.

2 likes
shez1983's avatar

normally you do a redirect after a form post - so you can return back with errors/success etc

1 like
tykus's avatar
tykus
Best Answer
Level 104

If you return a view, then you will need to prepare all of the data that view needs, which should not be the responsibility of a store action. By redirecting to the index action, the responsibility for organising the data and returning the data remain with that method, and store is responsibly only for handling the request, and returning the redirect.

1 like
mac03733's avatar

my main interest in using the named route, eg -> route('department.index') was to avoid modifying view('bluh bluh ') if i change folder structure.

Please or to participate in this conversation.