laravel-strapi
laravel-strapi copied to clipboard
An unknown Strapi error was returned while calling Route http://127.0.0.1:8000/test/2
Discussed in https://github.com/dbfx/laravel-strapi/discussions/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');
});

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 :

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

If anyonce can give me some insights would be really appreciated :) Thanks
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...
Thanks all, please try v2.0.2 now and see if fixed?
Tested & works! Thank you very much!
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.

Could anyone enlight me please :D
Here's a var_dump of the localite variable
