Jaylen Jaylen - 4 months ago 53
PHP Question

How can I use remember() method in Laravel to cache the query using query builder?

I have an application that is written using Laravel 5.2.

In many cases I am using query builder to build my queries like so

DB::connection('custom')->table('user')
->join
.....
->where(
........->get();


How can I use the method
remember()
to cache the query generated from the query builder?

I tried to use
->remember(60)
just before
get()
but this is giving me an error


Call to undefined method Illuminate\Database\Query\Builder::remember()

Answer

you should do this

 $value = Cache::remember('users', 60, function()
  {
     return DB::table('users')->get();
 });
Comments