Created
October 10, 2019 13:48
-
-
Save pawelmysior/b0347c94456bec354c49f485ebe2cae7 to your computer and use it in GitHub Desktop.
Cacheable settings model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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