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

我在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.

图片转代码服务由CSDN问答提供 功能建议

我在laravel中使用dingo / api。但它始终是错误404. 这是我的配置文件:

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

并且,在我的 config / app.php 输入 此处的图像说明

  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 
   
 
 

此外,我已经通过 php artisan vendor生成了 routes / api.php : 发布--provider =“Dingo \ Api \ Provider \ LaravelServiceProvider” \ n

这是我的 routes \ api.php

  $ api = app('Dingo \ Api \ Routing \ Router');  
 
 $ api->版本('v1',函数($ api){
 
 $ api-> group(['namespace'=>  'App \ Http \ Controllers \ Home'],函数($ api){
 $ api-> get('/ test','ULoginController @ register'); 
 
}); 
});  
   
 
 

这是我的项目结构: 在此输入图片说明

我需要你的帮助,谢谢。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题