Laravel 4: Redirect to a given url

PhpLaravelLaravel 4

Php Problem Overview


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');

Php Solutions


Solution 1 - Php

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);
}

Solution 2 - Php

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]);

Solution 3 - Php

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

Solution 4 - Php

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

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

Solution 5 - Php

This worked for me in Laravel 5.8

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

Or instead of / you can use

use Redirect;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOrvylView Question on Stackoverflow
Solution 1 - PhpThe AlphaView Answer on Stackoverflow
Solution 2 - PhpShubham GuptaView Answer on Stackoverflow
Solution 3 - Phpz2zView Answer on Stackoverflow
Solution 4 - PhpSheetal MehraView Answer on Stackoverflow
Solution 5 - PhpvimuthView Answer on Stackoverflow