Support the ongoing development of →
Cache Eloquent
Last updated 2 years ago.

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;
Last updated 7 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.