I ended up with this code which I use inside the model. I feel like it can be improved, but it works.
trait TestTrait
{
public static function fetchByName(string $name)
{
$self = new self;
$value = Cache::remember('test_' . $name, Config::get('cache.ttl'),
function() use ($name, $self) {
return $self::where('name', $name)->first();
});
return $value;
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community