php Laravel 4:重定向到给定的 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18626492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:55:34  来源:igfitidea点击:

Laravel 4: Redirect to a given url

phplaravellaravel-4

提问by Orvyl

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

laravel 的 Redirect 类中是否有参数是完整 url 的方法?我们都知道这些方法的参数只是路由名称、操作、斜线等,但我现在想要的是

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

回答by The Alpha

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):

更新:(Redirect::away('url')对于外部链接,Laravel 4.19 版):

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

回答by z2z

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

双方Redirect::to()Redirect::away()应工作。

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

区别

Redirect::to() 执行额外的 URL 检查和生成。这些额外的步骤在 Illuminate\Routing\UrlGenerator 中完成,如果传递的 URL 不是完全有效的 URL(即使使用协议),请执行以下操作:

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

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

源代码:https: //medium.com/@zwacky/laravel-redirect-to-vs-redirect-away-dd875579951f

回答by Shubham Gupta

You can use different types of redirect method in laravel -

您可以在 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]);

回答by Sheetal Mehra

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

您也可以使用这样的redirect()方法:-

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

回答by Aruna Perera

This worked for me in Laravel 5.8

这在 Laravel 5.8 中对我有用

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

Or instead of / you can use

或者代替 / 你可以使用

use Redirect;