Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An unknown Strapi error was returned while calling Route http://127.0.0.1:8000/test/2 #16

Open
bast111 opened this issue May 31, 2022 Discussed in #15 · 5 comments
Open

Comments

@bast111
Copy link

bast111 commented May 31, 2022

Discussed in #15

Originally posted by bast111 April 6, 2022
Hi guys, being fairly new to Laravel i wanted to start implement a strapi backend following that tutorial here

All worked fine at first, I created a route to fetch all my localites

Route::get('/test', function () {
    $strapi = new LaravelStrapi();
    return $localites = $strapi->collection('api/localites');
});

image

So I kept going and tried to create the route for one item

//Route pour 1 localite
Route::get('/test/{id}', function ($id) {
    $strapi = new LaravelStrapi();
    return $localites = $strapi->entry('api/localites', $id);
});

And this is what I get :
image

I can see that the api has been called successfully but I don't understand what is the problem
image

If anyonce can give me some insights would be really appreciated :) Thanks

@eblumstengel-dbkg
Copy link

eblumstengel-dbkg commented Jun 11, 2022

I have the exact same problem, which is caused by line 98 of the LaravelStrapi.php vendor class:

        if (!isset($entry['id'])) {
            Cache::forget($cacheKey);

            if (null === $entry) {
                throw new NotFound('The requested single entry (' . $type . ') was null');
            }

            throw new UnknownError('An unknown Strapi error was returned');
        }

As we can see in the screenshot postet above, the data returned via the API has a key "data" at the root level of the response. It seems the check for the entry in the LaravelStrapi.php class is not aware of that and only checks for the key "id", but lacks check of the "data" key. I changed this to:

if (!isset($entry['data']['id'])) {

and that resolves the problem, but is still a change in the vendor-file...

@dbfx
Copy link
Owner

dbfx commented Jun 13, 2022

Thanks all, please try v2.0.2 now and see if fixed?

@eblumstengel-dbkg
Copy link

Tested & works! Thank you very much!

@bast111
Copy link
Author

bast111 commented Jun 14, 2022

Amazing guys Thx for the fix it now works fine!

I do have another problem tho reaching the end of the tutorial.
I did a Route calling the Localite function in the LocaliteController. which return the localites.blade.php view... so far everything works fine
But when trying to access the fields from my Strapi object like the 'nom' or 'npa' it can't be found even id.
image

Could anyone enlight me please :D

@bast111
Copy link
Author

bast111 commented Jun 14, 2022

Here's a var_dump of the localite variable
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants