The prefix
method is located in the Illuminate\Routing\Router
class.
The absolute path in a typical Laravel 5 application would be:
vendor/laravel/framework/src/Illuminate/Routing/Router.php
How to find it?
You probably know that when you write Route::
you are actually using the Laravel facade called Route
. From there you can find the facade class reference in the official documentation of Laravel 5.4 at https://laravel.com/docs/5.4/facades#facade-class-reference. Here is the line you are looking for:
---------------------------------------------------------------
|Facade |Class |Service Container Binding |
---------------------------------------------------------------
|Route |Illuminate\Routing\Router |router |
---------------------------------------------------------------
The flow
- The (protected)
prefix
method is handled by the __call@Router
. return (new RouteRegistrar($this))->attribute($method, $parameters[0]);
is executed
- the
attribute@RouteRegistrar
method is called and the element 'prefix' => 'home'
is added to the $this->attributes
array
- Since the
attribute@RouteRegistrar
method returns $this
, the group@RouteRegistrar
method is called
- The
group@RouteRegistrar
method calls the group@Router
method
- The
loadRoutes@Router
method is called. It will parse all routes present in the closure, i.e. Route::get('/test', ...)
;
- This time the
get
method is called on the class underlying the Route
facade, the Router
class. The get@Router
method is executed
addRoute@Router
is called, which in turn calls the createRoute@Router
method
createRoute@Router
calls newRoute@Router
with the prefixed URI as second argument
You will notice that the prefix@Router
method calls getLastGroupPrefix@Router
which obviously retrieve the prefix of the last group.