Support the ongoing development of Laravel.io →
Input IOC Architecture

i want to add custom methods to my application router.

Route::get('email', 'Auth\PasswordController@getEmail')->icon('key');

What i did was create another class extending the Illuminate\Routing\Router then binded it in application service provider

        $this->app->bind('router', function ($app) {
            return new MyRouter($app['events'], $app);
        });

but this does not seem to be working. then i googled some more and came across this https://laracasts.com/discuss/channels/laravel/extending-the-illuminateroutingrouter-in-laravel-5-from-a-package but it doesn't work either.. any help would be nice.

Last updated 2 years ago.
0

Route::get() is returning a Illuminate\Routing\Route, so you would be calling icon() on Route not the Router.

If you wanted to extend the Router try looking at the newRoute method, which creates the new Route objects. Perhaps you can have that method using your extended version of Route, where you have added the icon method.

0

Hmm.. but on the Illuminate\Support\Facades\Route facade the getFacadeAccessor method is returning 'router' which is bound to Illuminate\Routing\Router ?

I'm trying to replace this binding but my replacement doesnt seem to be working properly.

0

Looks like that is being bound via Illuminate\Foundation\Application@registerBaseServiceProviders -> Illuminate\Routing\RoutingServiceProvider@register -> @registerRouter.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

astroanu astroanu Joined 22 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.