Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I was trying to cache the db query with built in function remember(). But it doesn't seem to be working fine. Here is fine snippets.

$categories = Category::orderBy('rank', 'asc')
            ->select('id', 'name', 'rank')
            ->where('parentid', '=', 0)
            ->where('id', '<>', 4)
            ->remember(300)
            ->get();

This is the reference link, which I was following. I am getting the following error messa

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

Category.php

<?php

namespace App;

use Eloquent;
use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
 //
}
like image 777
Anil Chaudhari Avatar asked Dec 30 '25 14:12

Anil Chaudhari


1 Answers

This functionality was removed in Laravel 5. However, you can still bring it back by following the tutorial behind this link. It's using the dwightwatson/rememberable package.

A better and future proof way of resolving this issue, is using the Cache method. This functionality is available from Laravel 4.2 onwards.

like image 61
Bram Verstraten Avatar answered Jan 01 '26 14:01

Bram Verstraten