gpt4 book ai didi

php - 显示 "message":"404 Not Found",同时使用 dingo 在 laravel 5.1 中创建 api

转载 作者:可可西里 更新时间:2023-11-01 13:00:48 24 4
gpt4 key购买 nike

我已经在 laravel 5.1 中配置了 dingo 包,但是当我尝试访问时

http://localhost:8000/test

显示以下错误

{"message":"404 Not Found","status_code":404,"debug":{"line":161,"file":"C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php","class":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException","trace":["#0 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(750): Illuminate\\Routing\\RouteCollection->match(Object(Dingo\\Api\\Http\\Request))","#1 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(659): Illuminate\\Routing\\Router->findRoute(Object(Dingo\\Api\\Http\\Request))","#2 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(635): Illuminate\\Routing\\Router->dispatchToRoute(Object(Dingo\\Api\\Http\\Request))","#3 C:\\wamp64\\www\\second\\vendor\\dingo\\api\\src\\Routing\\Adapter\\Laravel.php(81): Illuminate\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))","#4 C:\\wamp64\\www\\second\\vendor\\dingo\\api\\src\\Routing\\Router.php(513): Dingo\\Api\\Routing\\Adapter\\Laravel->dispatch(Object(Dingo\\Api\\Http\\Request), 'v1')","#5 C:\\wamp64\\www\\second\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php(126): Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))","#6 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}(Object(Dingo\\Api\\Http\\Request))","#7 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(139): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))","#8 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#9 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#10 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)","#11 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#12 [internal function]: Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#13 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)","#14 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(62): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#15 [internal function]: Illuminate\\Session\\Middleware\\StartSession->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#16 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)","#17 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#18 [internal function]: Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#19 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)","#20 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(59): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#21 [internal function]: Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#22 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)","#23 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(44): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#24 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))","#25 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)","#26 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))","#27 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))","#28 C:\\wamp64\\www\\second\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php(127): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","#29 C:\\wamp64\\www\\second\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php(103): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))","#30 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Illuminate\\Http\\Request), Object(Closure))","#31 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)","#32 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","#33 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))","#34 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(122): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","#35 C:\\wamp64\\www\\second\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(87): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))","#36 C:\\wamp64\\www\\second\\public\\index.php(54): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))","#37 C:\\wamp64\\www\\second\\server.php(21): require_once('C:\\\\wamp64\\\\www\\\\s...')","#38 {main}"]}}

我在 routes.php 中有以下代码

<?php

$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->get('test', 'App\Http\Controllers\ApiController@index');
});

Route::get('/', function () {
return view('welcome');
});

当你检查 api:route 时,它​​显示以下路由:

enter image description here

最佳答案

首先:你需要运行

php artisan api:cache

添加或编辑 routes.php 文件后。 Dingo API 从路由缓存中获取你的路由。您不能在路由文件中定义匿名函数。 Dingo 在缓存路由时出错。请将您的欢迎 View 移动到 Controller 的方法中。然后运行 ​​php artisan api:cache。我希望这会解决你的问题。此外,您可以检查第二个解决方案。

第二:

Dingo 有一些配置需要放在您的 .env 文件中。

API_PREFIX=api

告诉您所有的 api 端点都将以“api”为前缀。因此,您的测试 api 端点将是。

http://localhost:8000/api/test

关于php - 显示 "message":"404 Not Found",同时使用 dingo 在 laravel 5.1 中创建 api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42202610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com