Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Halim's avatar
Level 2

Partial Resource Routes NOT Working with Dingo API

I'm using Laravel 6.2, and : "dingo/api": "^2.4.0",

I have this code:

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

$api->version('v1', function ($api) {

    $api->resource('security-groups', 'App\Http\Controllers\Api\SecurityGroupsController')->only(['index',      'show']);

 });

When I do: php artisan api:routes I get an exception

Symfony\Component\Debug\Exception\FatalThrowableError  : Call to a member function only() on null

But If I remove the only at the end, it become working

Also with the apiResource:

$api->apiResource('security-groups', 'App\Http\Controllers\Api\Settings\SecurityGroupsController');

I get an exception as well:

 Symfony\Component\Debug\Exception\FatalThrowableError  : Call to undefined method 
 Dingo\Api\Routing\Router::apiResource()
0 likes
1 reply
Halim's avatar
Level 2

works like this:

    $api->resource('security-groups', 'App\Http\Controllers\Api\SecurityGroupsController',[
        'only' => ['index', 'show']
 ]);

But this still not working:

$api->apiResources('security-groups', 'App\Http\Controllers\Api\SecurityGroupsController');

Please or to participate in this conversation.