Laravel Redirect to URL using redirect() Helper

AuthorSumit Dey Sarkar

Pubish Date01 Feb 2024

categoryLaravel

In this tutorial, we will learn how to redirect to a URL using redirect() helper in Laravel.

Laravel Redirect to URL using redirect() Helper

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.

Comments 0

Leave a comment