0

I am preparing a bundle for Laravel4 and cannot find a way how I can add a configurable routes to my bundle.

Example:

//this is from the service provider of the bundle
public function register()
{
    ...
    $this->registerRoutes();
    ...
}

protected function registerRoutes()
{
     //The way of doing into the documentation or other bundles is
     //the problem is that I cannot put the routes to be from the config file
     //and they cannot be overwritten from the app configuration.
     include __DIR__ . '/routes.php';
}
//This method gives an error
protected function registerTestRoutes()
{
    $this->app['imager'] = $this->app->share(function($app)
        {
            //$route = 'admin/images/{$image_id}
            $route = $app['config']['imager::config']['delete_url'];
            return \Route::delete($route, array('uses' => 'CompanyName\Imager\Controllers\ImagerController@destroy'));;
        });
}
Jason Lewis
  • 18,537
  • 4
  • 61
  • 64
  • Please can you detail the error that you get, simply saying it gives an error does not help anyone to debug with you. – Phill Sparks Apr 11 '13 at 11:43

1 Answers1

0

Well I found a solution of the problem.

You don't have to create a configuration for that what should be the route into a bundle. It is enough to give it a name, so then when your bundle is used in multiple projects and some of them needs to change the url, the developers there, could simply put an alias.

// code from the SerivicePriveder
public function register()
{
...
$this->registerRoutes();
...
}

protected function registerRoutes()
{
 include __DIR__ . '/routes.php';
}

//code from the routes.php
<?php
Route::delete('admin/imager/{id}', array('as'=>'imager_delete', 'uses' => 'SixMinutes\Imager\Controllers\ImagerController@destroy'));

So, if it is needed to change 'admin/imager/{id}' you can just add an alias into the app/routes.php using the name 'imager_delete'