openfoodfacts/openfoodfacts-laravel

Assign geographic variable when OpenFoodFacts class is instantiated

n-va opened this issue · 2 comments

n-va commented

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.

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)