openfoodfacts / openfoodfacts-laravel

Open Food Facts API wrapper for Laravel
MIT License
151 stars 17 forks source link

Assign geographic variable when OpenFoodFacts class is instantiated #14

Closed n-va closed 6 months ago

n-va commented 2 years ago

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.

epalmans commented 2 years ago

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 commented 6 months ago

available now (^0.4.1)

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