openfoodfacts / openfoodfacts-laravel Goto Github PK
View Code? Open in Web Editor NEWOpen Food Facts API wrapper for Laravel
License: MIT License
Open Food Facts API wrapper for Laravel
License: MIT License
Hello, when i tried to install it in my project i had this error !
Problem 1
- openfoodfacts/openfoodfacts-laravel[dev-dependabot/github_actions/actions/cache-3.0.7, dev-explicit_geography, dev-master, v0.3.0] require openfoodfacts/openfoodfacts-php ^0.2.4 -> satisfiable by openfoodfacts/openfoodfacts-php[0.2.4].
- openfoodfacts/openfoodfacts-laravel v0.1 requires illuminate/support 5.7.x|5.8.x|^6.0|^7.0 -> found illuminate/support[v5.7.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but these were not loaded, likely because it conflicts with another require.
- openfoodfacts/openfoodfacts-laravel[v0.2, ..., v0.2.2] require illuminate/support 5.7.x|5.8.x|^6.0|^7.0|^8.0 -> found illuminate/support[v5.7.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.
- openfoodfacts/openfoodfacts-php 0.2.4 requires psr/log ^1.0 -> found psr/log[1.0.0, ..., 1.1.4] but the package is fixed to 3.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- Root composer.json requires openfoodfacts/openfoodfacts-laravel * -> satisfiable by openfoodfacts/openfoodfacts-laravel[dev-dependabot/github_actions/actions/cache-3.0.7, dev-explicit_geography, dev-master, v0.1, ..., v0.3.0, 9999999-dev].
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Can anyone help me in this ! Im junior developper so im not very experimented thanks !!
Epic: #
I tried to pass a product bar code number that did not existed yet, then added it by contributing through the OpenFoodFact Android App, then called the API again and still no product found.
I flushed my cache, called the method again, and this time the correct response is returned.
Only cache results for product found, do not cache product not found results (to allow subsequent retries to hopefully find the product if a contributor add it afterward).
OpenFoodFacts::barcode($code);
, where $code
is a bar code of a product not in the database yetOpenFoodFacts::barcode($code);
, where $code
is a bar code of the product just addedI noticed the cache is set after the JSON response it fetched. I did not dived into it in details, but if it is possible to figure out if the product is not found at this point, maybe we should prevent caching at this level?
https://github.com/openfoodfacts/openfoodfacts-php/blob/develop/src/Api.php#L431-L435
Edit: In fact, I just tried to dd at this point, by testing with product number "3760314500074", and the response is the following:
[
"code" => "3760314500074"
"status" => 0
"status_verbose" => "product not found"
]
So the fix for me (if you think it make sense), would be to update the code like this
class Api
{
// ...
private function fetch(string $url, bool $isJsonFile = true): array
{
// ...
$jsonResult = json_decode($response->getBody(), true);
- if (!empty($this->cache) && !empty($jsonResult)) {
+ if (!empty($this->cache) && !empty($jsonResult) && (($jsonResult["status"] ?? 0) !== 0) {
$this->cache->set($cacheKey, $jsonResult);
}
}
}
The geographic subdomain is assigned via the config:
parent::__construct([
'geography' => $app['config']->get('openfoodfacts.geography'),
'app' => $app['config']->get('app.name'),
], $app['cache.store']);
This doesn't allow for the API subdomain to be conditionally changed if the user is in another country. It would be great if this value could be assigned when the class instantiated.
The installation via composer doesn't work on Laravel 11.7.0
composer require openfoodfacts/openfoodfacts-laravel
on a Laravel project with version 11.7.0
Installing the package with composer :)
Problem 1
- openfoodfacts/openfoodfacts-laravel[v0.4.0, ..., v0.4.1] require openfoodfacts/openfoodfacts-php ^0.3.0 -> satisfiable by openfoodfacts/openfoodfacts-php[v0.3.0].
- openfoodfacts/openfoodfacts-laravel v0.1 requires illuminate/support 5.7.x|5.8.x|^6.0|^7.0 -> found illuminate/support[v5.7.0, ..., v5.8.36, v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6] but these were not loaded, likely because it conflicts with another require.
- openfoodfacts/openfoodfacts-laravel[v0.2, ..., v0.2.2] require illuminate/support 5.7.x|5.8.x|^6.0|^7.0|^8.0 -> found illuminate/support[v5.7.0, ..., v5.8.36, v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.
- openfoodfacts/openfoodfacts-laravel v0.3.0 requires illuminate/support ^9.0 -> found illuminate/support[v9.0.0, ..., v9.52.16] but these were not loaded, likely because it conflicts with another require.
- openfoodfacts/openfoodfacts-php v0.3.0 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension.
- Root composer.json requires openfoodfacts/openfoodfacts-laravel * -> satisfiable by openfoodfacts/openfoodfacts-laravel[v0.1, ..., v0.4.1].
Thank you!
I want to upgrade to Laravel 10 and the package does not support it.
Add support for Laravel 10.
Hi, there is one issue when installed
laravel 8.0
guzzle 7.2
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.2.0].
- Can only install one of: guzzlehttp/guzzle[7.2.0, 6.5.x-dev].
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.2.0].
- openfoodfacts/openfoodfacts-php 0.2.3 requires guzzlehttp/guzzle ^6.3 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- openfoodfacts/openfoodfacts-laravel v0.2 requires openfoodfacts/openfoodfacts-php ^0.2.3 -> satisfiable by openfoodfacts/openfoodfacts-php[0.2.3].
- Installation request for openfoodfacts/openfoodfacts-laravel ^0.2.0 -> satisfiable by openfoodfacts/openfoodfacts-laravel[v0.2].
- Installation request for guzzlehttp/guzzle (locked at 7.2.0, required as ^7.0.1) -> satisfiable by guzzlehttp/guzzle[7.2.0].
It is not possible to use openfoodfact with Laravel 11
Make it compatible :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.