What is the redirect() helper in Laravel?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Laravel development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

The redirect() helper generates a redirect response. Common uses: return redirect("/dashboard") (redirect to URL), return redirect()->route("dashboard") (redirect to named route), return redirect()->back() (redirect to previous page — useful after form validation failures), return redirect()->route("login"). Flash data to the next request: return redirect()->route("users.index")->with("success", "User created!") — access in Blade with session("success"). For redirects with old input (form re-population): return redirect()->back()->withErrors($validator)->withInput(). The Redirect facade provides the same functionality for non-response contexts.

Common Mistake

Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex Laravel answers easy to follow.