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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题