I'm trying to extend Laravel 5 core class. What i want to achieve is that i can have custom url generators eg. URL::test(), will generate custom link.
So far i have:
- Created app/Acme/lib folder
Added app/Acme/lib path to composer.json classmap
"autoload": { "classmap": [ .... app/Acme/lib ] }
Created custom UrlGenerator class in Acme/lib/CustomUrlGenerator.php
<?php namespace App\Acme\lib; use \Illuminate\Routing\UrlGenerator; class CustomUrlGenerator extends UrlGenerator { public function test() { return $this->to('/test'); } }
Created service provider app/Acme/lib/CustomUrlServiceProvider.php
<?php namespace App\Acme\lib; use \Illuminate\Routing\RoutingServiceProvider; class CustomUrlServiceProvider extends RoutingServiceProvider { public function boot() { App::bind('url', function() { return new CustomUrlGenerator( App::make('router')->getRoutes(), App::make('request') ); }); parent::boot(); } }
Registered service provider in app/config/app.php
- Run composer dump-autoload
Now when i run {!! URL::test() !!}, im getting 404 for every route
Sorry, the page you are looking for could not be found.
NotFoundHttpException in /vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php line 143:
Is there something that i'm missing? Many thanks for any help ..