Originally published on laravel.learnio.dev — part of the Laravel best practices course. View this lesson on the original site.
Return users to the right place predictably
Redirects are part of request flow, not an afterthought. Good redirect patterns make form and auth flows feel reliable.
Redirect to named routes by default
Prefer route names over hard-coded URLs:
return redirect()->route('orders.show', ['order' => $order->id]);
Or the shorthand:
return to_route('orders.show', ['order' => $order->id]);
This stays stable if URI paths change later.
Redirect back with input when validation fails
For form flows:
return back()->withInput();
This uses session flash data so fields can be repopulated in the next request.
Use intended redirects after auth
return redirect()->intended(route('dashboard'));
This sends users to the page they originally requested before login checks interrupted the flow.
Redirect status codes
Default redirects use 302. Use explicit status when needed:
return redirect()->route('home', [], 301);
Use 301 for permanent moves, 302 for standard post-action navigation.
Bad way vs better way
Bad way (hard-coded path strings):
return redirect('/orders/' . $order->id);
Better way (named route contract):
return to_route('orders.show', ['order' => $order->id]);
Why better:
- path refactors do not break redirects,
- intent is clearer in code review,
- route parameter mapping is explicit.
Practical redirect checklist
- prefer
to_route()orredirect()->route(), - use
back()->withInput()for failed form attempts, - use
intended()for auth return paths, - keep status codes explicit for permanent redirects.
Redirect flow
flowchart LR
A[Controller action result] --> B[Redirect decision]
B --> C[Named route or back or intended]
C --> D[Redirect response]
D --> E[Next request]
Next, you will apply redirect and middleware behaviour together in API and error-handling paths.
From Laravel best practices — Routing, Controllers & Request Flow