It's kind of pretty cumbersome to add the full name of a controller such as:
$api->version('v1', function($api) {
$api->get('user/{username}', 'App\Http\Controllers\v1\UserController@getUser');
});
Why can't it be something like this:
$api->version(['version' => 'v1, 'namespace' => 'App\Http\Controllers\v1\'], function($api) {
$api->get('user/{username}', 'UserController@getUser');
});
I saw nothing in the docs mentioning that issue, but its much neater to have the namespace set this way
You can, sort of:
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->group([
'namespace' => 'App\Http\Controllers\v1',
], function ($api) {
$api->get('foo', 'BarController@baz');
};
};
That should have been noted in the wiki, it makes much more sense like that.
you can also do this in your route service provider:
````php
/**
* Define the routes for the application.
*
* @param Illuminate\Routing\Router $router
* @param Dingo\Api\Routing\Router $apiRouter
* @return void
*/
public function map(Router $router, DingoRouter $apiRouter)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
});
$apiRouter->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
});
}
````
Most helpful comment
You can, sort of: