我在Laravel中的API路由上遇到错误。我用过Dingo包。成功安装,在app.php中添加,由artisan生成api.php。
在路由器文件中,代码为: -
use Dingo\Api\Routing\Helpers;
$api = app('Dingo\Api\Routing\Router');
/*$api = app('Dingo\Api\Facade\Route');*/
$api->version('v1', function($api){
$api->get('hello', function(){
return "Hello !!!!!";
});
});
在使用php artisan api:routes进行检查时,我正在获得这样的路线/ api / routes /。但是,当我点击网址时,有一个很长的错误: -
{"message":"404 Not Found","status_code":404,"debug":{"line":179,"file":"\/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/RouteCollection.php","class":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException","trace":["#0 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(612): Illuminate\\Routing\\RouteCollection->match(Object(Dingo\\Api\\Http\\Request))","#1 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(601): Illuminate\\Routing\\Router->findRoute(Object(Dingo\\Api\\Http\\Request))","#2 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(590): Illuminate\\Routing\\Router->dispatchToRoute(Object(Dingo\\Api\\Http\\Request))","#3 \/var\/www\/html\/exam\/vendor\/dingo\/api\/src\/Routing\/Adapter\/Laravel.php(81): Illuminate\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))","#4 \/var\/www\/html\/exam\/vendor\/dingo\/api\/src\/Routing\/Router.php(512): Dingo\\Api\\Routing\\Adapter\\Laravel->dispatch(Object(Dingo\\Api\\Http\\Request), 'v1')","#5 \/var\/www\/html\/exam\/vendor\/dingo\/api\/src\/Http\/Middleware\/Request.php(126): Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))","#6 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(114): Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}(Object(Dingo\\Api\\Http\\Request))","#7 \/var\/www\/html\/exam\/vendor\/fideloper\/proxy\/src\/TrustProxies.php(56): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#8 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(149): Fideloper\\Proxy\\TrustProxies->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#9 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/TransformsRequest.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#10 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#11 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/TransformsRequest.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#12 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#13 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#14 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#15 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/CheckForMaintenanceMode.php(46): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#16 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#17 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(102): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#18 \/var\/www\/html\/exam\/vendor\/dingo\/api\/src\/Http\/Middleware\/Request.php(127): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","#19 \/var\/www\/html\/exam\/vendor\/dingo\/api\/src\/Http\/Middleware\/Request.php(103): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))","#20 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(149): Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#21 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","#22 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))","#23 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","#24 \/var\/www\/html\/exam\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))","#25 \/var\/www\/html\/exam\/public\/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))","#26 \/var\/www\/html\/exam\/server.php(21): require_once('\/var\/www\/html\/e...')","#27 {main}"]}}
答案 0 :(得分:1)
我得到了答案。 我在尝试使用localhost。 我为API_DOMAIN和API_PREFIX提供了值。但是,必须知道在这种情况下不需要API_DOMAIN。