@ssquare You could create a SettingsRepository that encapsulates the caching logic. Your application can then call a method on this repository and retrieve the settings and not care if the settings came from the cache or if they came from the database:
class SettingsRepository
{
public function all()
{
return Cache::rememberForever('settings', function () {
return Setting::pluck('value', 'key');
});
}
public function get($key, $default = null)
{
return $this->all()->get($key, $default);
}
}
Now, you can type-hint this repository where ever you need settings in your application:
class SomeController extends Controller
{
protected $settings;
public function __construct(SettingsRepository $settings)
{
$this->settings = $settings;
}
public function someAction()
{
$adminEmail = $this->settings->get('adminEmail');
// Do something with $adminEmail...
}
}
If you do cache settings, just be sure to clear the cache when you add/edit/remove a setting value from the database.