Orvyl
Orvyl

Reputation: 2775

Redirect to a given Laravel URL

Is there a method in Redirect class of laravel where the parameter is a complete url? We all know parameters to these methods are just route name,action, slash,..etc but what I want now is like

return Redirect::foo('https://bla.com/?yken=KuQxIVTNRctA69VAL6lYMRo0');

Upvotes: 73

Views: 276486

Answers (6)

Ajay
Ajay

Reputation: 888

we can use in the latest Laravel version

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

if want to pass query param:

  $redirectUrl = $request->redirect_url.'/reset-password?token='.$request->token.'&email='.$request->email;

 return redirect()->away($redirectUrl);

Upvotes: -1

The Alpha
The Alpha

Reputation: 146191

Yes, it's

use Illuminate\Support\Facades\Redirect;

return Redirect::to('http://heera.it');

Check the documentation.

Update: Redirect::away('url') (For external link, Laravel Version 4.19):

public function away($path, $status = 302, $headers = array())
{
    return $this->createRedirect($path, $status, $headers);
}

Upvotes: 111

vimuth
vimuth

Reputation: 5602

This worked for me in Laravel 5.8

return \Redirect::to('https://bla.com/?yken=KuQxIVTNRctA69VAL6lYMRo0');

Or instead of / you can use

use Redirect;

Upvotes: 1

Shubham Gupta
Shubham Gupta

Reputation: 331

You can use different types of redirect method in laravel -

return redirect()->intended('http://heera.it');

OR

return redirect()->to('http://heera.it');

OR

use Illuminate\Support\Facades\Redirect;

return Redirect::to('/')->with(['type' => 'error','message' => 'Your message'])->withInput(Input::except('password'));

OR

return redirect('/')->with(Auth::logout());

OR

return redirect()->route('user.profile', ['step' => $step, 'id' => $id]);

Upvotes: 27

Sheetal Mehra
Sheetal Mehra

Reputation: 518

You can also use redirect() method like this:-

return redirect('https://stackoverflow.com/');

Upvotes: 6

z2z
z2z

Reputation: 529

Both Redirect::to() and Redirect::away() should work.

Difference

Redirect::to() does additional URL checks and generations. Those additional steps are done in Illuminate\Routing\UrlGenerator and do the following, if the passed URL is not a fully valid URL (even with protocol):

Determines if URL is secure
rawurlencode() the URL
trim() URL

src : https://medium.com/@zwacky/laravel-redirect-to-vs-redirect-away-dd875579951f

Upvotes: 4

Related Questions