Laravel 4: Redirect to a given url

后端 未结 5 1181
一生所求
一生所求 2020-12-25 10:28

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 wha

相关标签:
5条回答
  • 2020-12-25 10:37

    This worked for me in Laravel 5.8

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

    Or instead of / you can use

    use Redirect;
    
    0 讨论(0)
  • 2020-12-25 10:51

    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);
    }
    
    0 讨论(0)
  • 2020-12-25 10:55

    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

    0 讨论(0)
  • 2020-12-25 10:56

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

    return redirect('https://stackoverflow.com/');
    
    0 讨论(0)
  • 2020-12-25 10:57

    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]);
    
    0 讨论(0)
提交回复
热议问题