I am trying to extend the main Laravel 5 class. What I want to achieve is that I can have custom url generators, for example. URL :: test () will generate a custom link.
So far, I:
- Created application / folder Acme / lib
Added / Acme / lib application interface to classmap composer.json
"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 Application /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 the application /config/app.php
- Starting the dump-autoload linker
Now when I run {!! URL :: test () !!}, im gets 404 for each 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 I am missing? Thanks so much for any help ..