API参数不通过
我将Laravel 7与Vue 2一起使用,以在着陆页面上显示一些结果。我想以这种方式将数据从对象传递到符号的API。
// file config/posts.php
[
"id" => 1,
"name" => "...",
"description" => "...",
"github_url" => "...",
"site_url" => "...",
"imgs" => [
"img1" => "...",
"img2" => "...",
"img3" => "...",
],
],
// file api.php
Route::namespace('Api')->group(function () {
Route::get('/', 'PostController@index');
Route::get('/posts/{id}', 'PostController@show');
});
当我想单击一个元素并通过API单击的元素结果时,我会有问题。在我的postcontroller@show函数中,我构造了数据以传递:
49 public function show($id)
50 {
51 $posts = config('posts');
52 $post = $posts->find($id);
53
54 return response()->json(compact('post'));
}
API的结果给了我一个错误:
错误:call in File App \ http \ controllers \ api \ arnay上的成员函数find() postController.php在第52行
我该如何修复?谢谢你!
I'm using Laravel 7 with Vue 2 to show some results on landing pages. I wanted to pass the data from an object to an API stuctured in this way.
// file config/posts.php
[
"id" => 1,
"name" => "...",
"description" => "...",
"github_url" => "...",
"site_url" => "...",
"imgs" => [
"img1" => "...",
"img2" => "...",
"img3" => "...",
],
],
// file api.php
Route::namespace('Api')->group(function () {
Route::get('/', 'PostController@index');
Route::get('/posts/{id}', 'PostController@show');
});
I have a problem when i want to click on a single element and get the results of the element I clicked on through the API. In my PostController@show function I structured the data to pass as so:
49 public function show($id)
50 {
51 $posts = config('posts');
52 $post = $posts->find($id);
53
54 return response()->json(compact('post'));
}
The result of the API gives me an error:
Error: Call to a member function find() on array in file app\Http\Controllers\Api\PostController.php on line 52
How can I fix this? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论