简体   繁体   English

重定向到给定的 Laravel URL

[英]Redirect to a given Laravel URL

Is there a method in Redirect class of laravel where the parameter is a complete url? laravel 的 Redirect 类中是否有参数是完整 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');

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

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

Both Redirect::to() and Redirect::away() should work. Redirect::to()Redirect::away()都应该工作。

Difference区别

Redirect::to() does additional URL checks and generations. Redirect::to() 执行额外的 URL 检查和生成。 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):这些附加步骤在 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

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

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

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;

we can use in the latest Laravel version我们可以在最新的 Laravel 版本中使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM