I'd probably use a settings file for this and then load them into config on each request cycle.
You could use Spatie valuestore for this https://github.com/spatie/valuestore/#usage
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using some conversion rates inside my application. They are fetched every n minutes and stored inside a "config" table.
Each product has an accessor like this:
public function getPriceEUR()
{
return intval($this->usd_price / SystemConfig::find(1)->value * 100);
}
I'm using this way to make sure I don't overload a webAPI. I figured out a problem, when displaying many products in a listing.
Every product listing will result in 1 database call to load SystemConfig::find(1)->value. This is for sure not a good way to go, using eager loading all the time and now this...any suggestions?
How about;
Install Valuestore composer require spatie/valuestore
In AppServiceProvider register method;
public function register()
{
$this->app->singleton('valuestore', function () {
return \Spatie\Valuestore\Valuestore::make(storage_path('app/settings.json'));
});
$values = $this->app->valuestore->all();
$this->app->bind('settings', function () use($values) {
return $values;
});
}
What we have in the app container is a singleton that points to the valuestore class. When you use that, you are directly interacting with the settings stored in the file.
When you use the settings bound to the app container, you are using a cached version of the values as they were at the start of the request cycle (as an associated array).
So instead of writing the current Euro rate to a database row, put it in the valuestore instead;
app('valuestore')->put('EUR', $rate)
and in your model when you want to apply this;
public function getPriceEUR()
{
return intval($this->usd_price / app('settings')['EUR'] * 100);
}
By using settings and not valuestore the file will only be accessed once and not each time you iterate over the products.
Of course you now have a place where you can store other currencies or any other application settings.
Please or to participate in this conversation.