Dingoを使用してAPIを構築しています。この時点までは、ルートに問題はありませんでした。コントローラにshowを追加しようとするまで、私は404 。ここLaravel Dingo API Route 404 for @show
詳細:ここ
{
"error": {
"message": "404 Not Found",
"status_code": 404,
"debug": {
"line": 179,
"file": "/var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"class": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"trace": [
"#0 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(546): Illuminate\\Routing\\RouteCollection->match(Object(Dingo\\Api\\Http\\Request))",
"#1 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(525): Illuminate\\Routing\\Router->findRoute(Object(Dingo\\Api\\Http\\Request))",
"#2 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(511): Illuminate\\Routing\\Router->dispatchToRoute(Object(Dingo\\Api\\Http\\Request))",
"#3 /var/www/html/myapi/api/vendor/dingo/api/src/Routing/Adapter/Laravel.php(81): Illuminate\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))",
"#4 /var/www/html/myapi/api/vendor/dingo/api/src/Routing/Router.php(513): Dingo\\Api\\Routing\\Adapter\\Laravel->dispatch(Object(Dingo\\Api\\Http\\Request), 'v1')",
"#5 /var/www/html/myapi/api/vendor/dingo/api/src/Http/Middleware/Request.php(126): Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))",
"#6 /var/www/html/myapi/api/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/myapi/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
"#8 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
"#9 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
"#10 /var/www/html/myapi/api/vendor/dingo/api/src/Http/Middleware/Request.php(127): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
"#11 /var/www/html/myapi/api/vendor/dingo/api/src/Http/Middleware/Request.php(103): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))",
"#12 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
"#13 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
"#14 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))",
"#15 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
"#16 /var/www/html/myapi/api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))",
"#17 /var/www/html/myapi/api/public/index.php(54): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))",
"#18 {main}"
]
}
}
}
は私のルートファイル api.php
$api->group(['middleware' => 'jwt.auth'], function(Router $api) {
$api->get('protected', function() {
return response()->json([
'message' => 'Access to protected resources granted! You are seeing this text as you provided the token correctly.'
]);
});
$api->get('refresh', [
'middleware' => 'jwt.refresh',
function() {
return response()->json([
'message' => 'By accessing this endpoint, you can refresh your access token at each request. Check out this response headers!'
]);
}
]);
$api->get('leads', 'App\\Api\\V1\\Controllers\\[email protected]');
$api->get('leads/{$id}', 'App\\Api\\V1\\Controllers\\[email protected]');
$api->post('leads/store', 'App\\Api\\V1\\Controllers\\[email protected]');
$api->put('leads/update/{$id}', 'App\\Api\\V1\\Controllers\\[email protected]');
$api->post('leads/update/{$id}', 'App\\Api\\V1\\Controllers\\[email protected]');
});
の部分およびshow楽しいですコントローラでction: LeadController.php
public function show(Lead $leads, $id)
{
dd($id);
$lead = Lead::with('user', 'source', 'industry', 'status')->find($id);
//if(!$lead)
// return $this->response->error('invalid_data', 400);
//return fractal($lead, new LeadTransformer())->respond();
}
私はIDが通過来ていることを確認するためにDie'n'Dumpを行うことを試みましたが、それはそこまできているようには見えません。 @indexと@storeの両方が問題なく動作し、LeadController @ indexをLeadController @ showに変更すると、ルートが機能し、もちろん2番目のパラメータに関するエラーが発生します。
本当にこれがうまくいかない理由で本当に紛失してしまったので、ここで本当に感謝します。変数は、それが持つべきであるとして{$番号}ない{ID}として設定されたため、十分な睡眠をあまりにもハード見て、そしてないから、それが機能しなかった理由だった