Ad
Laravel Routing: Where Is The Prefix() Method Defined?
In my example, I defined a route:
Route::prefix('home')->group(function(){
Route::get('/test',....);
});
When I access mydomain/home/test,
it works. However, I don't know where the prefix
method is located. I think it might be in Illuminate\Routing\Route.php.
But when I remove the prefix
method on that, is it still working?
Ad
Answer
@louisfischer answer is incorrect. The Router::prefix
is not called at all.
The prefix
method is called from RouteRegistrar
, which is finally forwarded to the RouteRegistrar::attribute
method.
You can verify this by looking in the Illuminate\Support\Facades\Route
docblock.
* @method static \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
Here is the complete flow:
- The Route facade first forwards the call to
Illuminate\Routing\Router
throughFacade::__callStatic
. - Since
Router::prefix
is not apublic
method but aprotected
method, this call is forwarded toRouteRegistrar::attribute
through theRouter::__call
method. - Finally the
prefix($url)
method is converted toRouteRegistrar::attribute('prefix', $url)
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad