The
redirect
function returns a redirect HTTP response, or returns the redirector instance if called with no arguments:<?php return redirect($to = null, $status = 302, $headers = [], $https = null);
return redirect('/home');
return redirect()->route('route.name');
<?php return (new FirstPage)();
})->middleware('web');
Route::get('/first-outside', FirstPageWithLinkOutside::class)->middleware('web');
Route::get('/redirect-to-second', fn () => redirect()->to('/second'));
Route::get('/second', SecondPage::class)->middleware('web');
Route::get('/third', ThirdPage::class)->middleware('web');
Route::get('/fourth', FourthPage::class)->middleware('web');
<?php {
public function redirectToPageOne()
{
return redirect('/first');
}
public function render()
<?php Route::get('awesome-js/{framework}', ComponentWithModel::class)
->missing(function (Request $request) {
$this->assertEquals(request(), $request);
return redirect()->to('awesome-js/alpine');
});
$this->get('/awesome-js/jquery')->assertRedirect('/awesome-js/alpine');
<?php }
if ($to && ! app(HandleRequests::class)->isLivewireRequest()) {
abort(redirect($to));
}
if (! $to) return;
<?php public function triggerRedirectHelper()
{
return redirect('foo');
}
public function triggerRedirectHelperUsingKeyValueWith()
<?php public function triggerRedirectHelperUsingKeyValueWith()
{
return redirect('foo')->with('success', 'livewire-is-awesome');
}
public function triggerRedirectHelperUsingArrayWith()
<?php public function triggerRedirectHelperUsingArrayWith()
{
return redirect('foo')->with([
'success' => 'livewire-is-awesome'
]);
}
<?php public function triggerRedirectHelperUsingRoute()
{
return redirect()->route('foo');
}
public function triggerRedirectHelperUsingAway()
<?php public function triggerRedirectHelperUsingAway()
{
return redirect()->away('foo');
}
public function render()
<?php {
$this->skipRender();
return redirect('/bar');
}
public function render()
<?php foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect($this->redirectTo($request));
}
}
<?php {
return $this->shouldReturnJson($request, $exception)
? response()->json(['message' => $exception->getMessage()], 401)
: redirect()->guest($exception->redirectTo($request) ?? route('login'));
}
<?php protected function invalid($request, ValidationException $exception)
{
return redirect($exception->redirectTo ?? url()->previous())
->withInput(Arr::except($request->input(), $this->dontFlash))
->withErrors($exception->errors(), $request->input('_error_bag', $exception->errorBag));
}
<?php function to_route($route, $parameters = [], $status = 302, $headers = [])
{
return redirect()->route($route, $parameters, $status, $headers);
}
}
<?php : trim($data['redirect'], '/');
if ($request->path() !== $path) {
return redirect($path);
}
}