-1

我正在尝试使用以下代码过滤缓存数据

$Categories = \Cache::rememberForever('Categories', function() {
    return \App\Models\Skill\Category_Model::all();
});

$Category = $Categories::where("CategoryID", "=", $id)->first();

错误详情 :

非静态方法 Illuminate\Support\Collection::where() 不应被静态调用,假设 $this 来自不兼容的上下文

我错过了什么吗?

我的意思是,过滤缓存对象中数据的最快方法是什么。缓存对象是一个模型。Categories 数组包含模型的集合,其中包含 categoryID ID。我想根据 CategoryID 过滤数据

4

1 回答 1

1

你应该使用:

$Categories->where("CategoryID", $id)->first();
// or
$Categories->where("CategoryID", '=', $id)->first();

where不能静态调用。结帐课Illuminate\Support\Collection

编辑:

您只能按照您尝试的方式在 Eloquent 模型上将其称为静态。而且因为您已经获取了结果(进入集合)。

于 2015-12-18T11:10:58.340 回答