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
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
If it's a form why not just store the view name in a hidden input and send it along with the rest of the form data.
Form::hidden('view', 'model.index')
I don't think there's a way to get the current view name but you can pass the view name to the view from the originating controller when you set the view to use in the first place:
public function create()
{
$myView = 'model.index';
Return View::make($myView)->with(compact('myView'));
}
Then the $myView
variable containing the view name is available for inserting in the form, as described above.
In the receiving controller (your store
method) just retrieve it from the form data with Input::get('view')
.