In this tutorial, we will learn how to redirect to a URL using redirect() helper in Laravel.
Laravel redirect to URL using redirect() helper
Here we used redirect()
helper function to redirect a user to a specific URL.
Let's see an example:
use Illuminate\Support\Facades\Redirect;
// ...
public function redirectToURL()
{
$url = 'https://example.com'; // Replace this with your desired URL
return redirect($url);
}
Alternatively, you can use the redirect()->away()
method:
use Illuminate\Support\Facades\Redirect;
// ...
public function redirectToURL()
{
$url = 'https://example.com'; // Replace this with your desired URL
return redirect()->away($url);
}
Both methods have the same result, so you can choose the one that is good for you.