Hi,
I've been looking at Cache docs: http://laravel.com/docs/5.0/cache
I want to use Cache in my models, so I was thinking like this:
class Question extends Eloquent
{
...
public function scopeGetNewest($query)
{
if (Cache::has('newest'))
{
return Cache::get('newest')
}
$newest = $query->where(...)->get();
Cache::put('newest', $newest, 120); // 2 hrs
return $newest;
}
}
..but this isn't going to let me mock the Cache object in tests :/
How should I do this? Should I pass the cache object in with the models constructor:
public function __construct($cache)
{
$this->cache = $cache;
}
Is there anyway to handle this via IoC?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community