Laravel: Get the name of the view that called the controller method

前端 未结 2 1095
忘掉有多难
忘掉有多难 2021-01-28 18:24

In laravel is it possible to get the name of the view that called the controller method that you\'re currently in?

I have two version of a form in my site. One is meant

2条回答
  •  迷失自我
    2021-01-28 18:58

    This is how you can achieve that. Just do this in the controller method where you want to detect the previous route name from which came the request.

            $url = url()->previous();
    
            $route = app('router')->getRoutes($url)->match(app('request')->create($url))->getName();
            
            if($route == 'route name here') {
                return redirect()->back(); //example
            }
    
            return view('users.index'); //example
    

提交回复
热议问题