dprlv04662 2018-04-03 01:41
浏览 996
已采纳

我在laravel中使用dingo / api。但它始终是错误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.

  • 写回答

1条回答 默认 最新

  • dsgw8802 2018-04-03 03:03
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号