API参数不通过

发布于 2025-02-10 04:37:06 字数 1001 浏览 2 评论 0原文

我将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文