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

我在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 关于#linux#的问题(输入输出错误):出现这个界面接着我重新装系统,又让修电脑的师傅帮我扫描硬盘(没有问题)用着用着又卡死(相关搜索:固态硬盘)
  • ¥15 cv::resize不同线程时间不同
  • ¥15 web课程,怎么做啊😭没好好听课 根本不知道怎么下手
  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释
  • ¥15 python提取.csv文件中的链接会经常出现爬取失败
  • ¥15 数据结构中的数组地址问题
  • ¥15 maya的mel里,怎样先选择模型A,然后利用mel脚本自动选择有相同名字的模型B呢。
  • ¥15 Python题,根本不会啊
  • ¥15 会会信号与系统和python的来
  • ¥15 关于#python#的问题