API parameters not passing

Viewed 21

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!

0 Answers
Related