Search code examples
phplaravelhttp-status-code-404dingo-api

I use dingo/api in laravel.But it's always error 404


I use dingo/api in laravel.But it's always error 404. This is my config file:

# dingo/api`  
API_STANDARDS_TREE=vnd  
API_SUBTYPE=ipr  
API_PREFIX=api  
API_VERSION=v1  
API_DEBUG=true  

And ,in my config/app.php enter image description here

App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
// RepositoryServiceProvider
Prettus\Repository\Providers\RepositoryServiceProvider::class,
// Dingo
Dingo\Api\Provider\LaravelServiceProvider::class

Also, I have generated routes/api.php by php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"

This is My routes\api.php :

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

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

    $api->group(['namespace' => 'App\Http\Controllers\Home'], function($api) {
        $api->get('/test', 'ULoginController@register');

    });
});

This is my project structure: enter image description here

I need your help, Thanks.


Solution

  • Change this

    $api->group(['namespace' => 'App\Http\Controllers\Home'], function($api) {
        $api->get('/test', 'ULoginController@register');
    
    });
    

    To

    $api->group(['namespace' => 'App\Http\Controllers\Home'], function($api) {
        $api->get('/test', 'App\Http\Controllers\ULoginController@register');
    
    });
    

    Why? Because Dingo uses a separate logic for loading controllers to differentiate between Laravel and Dingo API's controller.

    That's why you have to manually call the controller path