How To Redirect To External Domains In Laravel Framework

admin_img Posted By Bajarangi soft , Posted On 17-09-2020

Laravel Redirect responses are instances of the Illuminate\Http\RedirectResponse class, and contain the proper headers needed to redirect the user to another URL. There are several ways to generate a RedirectResponse instance.Laravel has a useful function redirect() to redirect a user to a different page or action, with or without data.Visit

How To Redirect To External Domains In Laravel Framework

To know more about HTTP Redirects Visit Bajarangisoft site

Redirecting To External Domains

Sometimes you may need to redirect to a domain outside of your application. You may do so by calling the away method, which creates a RedirectResponse without any additional URL encoding, validation, or verification:
 

return redirect()->away('https://www.google.com');
 

Redirecting With Flashed Session Data

Redirecting to a new URL and flashing data to the session are usually done at the same time. Typically, this is done after successfully performing an action when you flash a success message to the session. For convenience, you may create a RedirectResponse instance and flash data to the session in a single, fluent method chain:
 

Route::post('user/profile', function () {
// Update the user's profile...

return redirect('dashboard')->with('status', 'Profile updated!');
});


After the user is redirected, you may display the flashed message from the session.

For example, using Blade syntax:

@if (session('status'))
<div class="alert alert-success">
    {{ session('status') }}
</div>
@endif

Related Post