简体   繁体   English

如何重定向到Laravel 5.6中的预期URL

[英]How to redirect to a previous URL in Laravel 5.6 and intended

In my Laravel application I have a middleware for specific routes, in this middleware I validate to redirect to a url. 在我的Laravel应用程序中,我具有用于特定路由的中间件,在此中间件中,我验证了重定向到url的能力。

public function handle($request, Closure $next)
{
    $isValidated= ....
    if ($isValidated) {
        session()->put('url.intended', URL::full());
        return redirect()->route('routeone')
    }
    return $next($request);
}

in the store method of that table when you register I do a redirect in the following way, but it turns out that when I do it, it redirects me to domain/img/favicon.png and I did not do the previous route 在您注册时在该表的store方法中按以下方式进行重定向,但事实证明,当我这样做时,它会将我重定向到domain/img/favicon.png而我没有执行上一条路由

public function store(Request $request)
{
    ....
    return redirect()->intended(session('url.intended') ?? '/admin');
}

What is the problem here or how could I address this detail to redirect to the url before the middleware redirects. 这是什么问题,或者在中间件重定向之前,我该如何解决此详细信息以将其重定向到url。 ?

Try to use this code : 尝试使用此代码:

$referrer = $this->request->headers->get('referer');

$url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession();

or directly : 或直接:

$url = request()->headers->get('referer');

and

session()->put('url.intended', $url);

Could you not just do this 你能不能这样做

return back();

From the docs https://laravel.com/docs/5.7/redirects#creating-redirects 从文档https://laravel.com/docs/5.7/redirects#creating-redirects

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

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