openfoodfacts-laravel icon indicating copy to clipboard operation
openfoodfacts-laravel copied to clipboard

Assign geographic variable when OpenFoodFacts class is instantiated

Open n-va opened this issue 2 years ago • 1 comments

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.

n-va avatar Mar 14 '22 21:03 n-va

we are open to PR's ofcourse, but alternatively, you could try to change the geography config setting at runtime before calling the OpenFoodFacts class (or through its facade), e.g.

Config::set('openfoodfacts.geography', 'fr');
$openfoodfacts = app(OpenFoodFacts::class);

// $openfoodfacts->barcode('20203467');

(note: untested code)

epalmans avatar Mar 15 '22 10:03 epalmans

available now (^0.4.1)

See https://github.com/openfoodfacts/openfoodfacts-laravel/pull/22

epalmans avatar May 01 '24 20:05 epalmans