Search code examples
phpapilaraveldingo-api

Laravel 5.2 Dingo/api resources group


As the title mentions, I am trying to figure out how to make a resource group by dingo.

As it explains with laravel, the correct way to make a resource group in route is:

Route::resource('item', 'Api\ItemController');

is it similar with the dingo/api? can I just say:

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', function($api){
    $api->resources('item','App\Http\Controllers\Api\ItemController');
});

When executing this way, i get a type error:

Argument 1 passed to Dingo\Api\Routing\Router::resources() must be of the type array, string given

Does this mean that I have to make an array of all the calls that I need and then pass it to the resources method?


Solution

  • You have a typo there. The actual method is resource not resources

    $api->version('v1', function($api){
        $api->resource('item','App\Http\Controllers\Api\ItemController');
    });