Skip to content

Instantly share code, notes, and snippets.

@pawelmysior
Created October 10, 2019 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawelmysior/b0347c94456bec354c49f485ebe2cae7 to your computer and use it in GitHub Desktop.
Save pawelmysior/b0347c94456bec354c49f485ebe2cae7 to your computer and use it in GitHub Desktop.
Cacheable settings model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
class Setting extends Model
{
protected static function boot()
{
static::saved(function () {
Cache::forget('settings.year');
});
}
public static function getYear()
{
return Cache::rememberForever('settings.year', function () {
return static::where('key', 'year')->first()->value;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment