I am trying to access the name of the current controller and the current method in order to pass it to my view as a variable. I tried several methods from pointers that I found on the Internet, but they do not work, so I assume they are for Laravel 3.
Here is what I tried
Request::$route->controller
gives
Access to undeclared static property: Illuminate\Support\Facades\Request::$route
and
Request::route()->controller
Call to undefined method Illuminate\Http\Request::route()
The Router instance in each request has the following methods that may be useful:
Router
/** * Retrieve the entire route collection. * * @return \Symfony\Component\Routing\RouteCollection */ public function getRoutes() { return $this->routes; } /** * Get the current request being dispatched. * * @return \Symfony\Component\HttpFoundation\Request */ public function getRequest() { return $this->currentRequest; } /** * Get the current route being executed. * * @return \Illuminate\Routing\Route */ public function getCurrentRoute() { return $this->currentRoute; } /** * Get the controller inspector instance. * * @return \Illuminate\Routing\Controllers\Inspector */ public function getInspector() { return $this->inspector ?: new Controllers\Inspector; }
Route::currentRouteAction()
returns e..g "RecordAPIController @show"
Try assigning routes according to, and then using $name = Route::currentRouteName();
$name = Route::currentRouteName();
In what state do you not know that the controller / route was fired ahead of time? Can you tell us what is your use case?
Laravel used "Request" as an alias for "Illuminate \ Support \ Facades \ Request" (can be found in app.php). My advice is to avoid using "Query" as the model / controller / view name.
You can use the basic constants / functions of php and not Laravel:
__LINE__, __FILE__, __FUNCTION__, __CLASS__, __METHOD__
will give you the current line, file, function, class or method
get_class()
provides the current class
Source: https://habr.com/ru/post/949901/More articles:left and right alignment lines inside Listview? - androidstring :: erase (0) on an empty string? - c ++ORDER BY not working correctly? - sqlTextview onclicklistener with links - androidDoes hibernate use PreparedStatement by default - javaWhere are variables stored in Python? - pythonPython xlwt: save all styles, but one - pythonThe implementation of Trie in Guava? - javaSystem.Object Portable Class Library Error - .net-4.5How can I take the square root of -1 using python? - pythonAll Articles