我正在为Laravel4准备一个包,但找不到如何为我的包添加可配置路由的方法。
示例:
//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'));;
});
}
答案 0 :(得分:0)
我找到了问题的解决方案。
您不必为应该成为捆绑包的路径创建配置。它足以为它命名,所以当你的bundle在多个项目中使用时,其中一些需要更改url,那里的开发人员可以简单地添加一个别名。
// 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'));
因此,如果需要更改'admin / imager / {id}',您只需使用名称'imager_delete'
在app / routes.php中添加别名即可