我正在尝试使用以下代码筛选缓存数据
$Categories = 'Cache::rememberForever('Categories', function() {
return 'App'Models'Skill'Category_Model::all();
});
$Category = $Categories::where("CategoryID", "=", $id)->first();
错误详细信息:
非静态方法Illuminate''Support''Collection::where()不应为静态调用,假设$this来自不兼容的上下文
我错过了什么吗
我的意思是,什么是过滤缓存对象中数据的最快方法。缓存对象是一个模型。Categories Array包含包含categoryID ID的Model集合。我想根据categoryID 筛选数据
您应该使用:
$Categories->where("CategoryID", $id)->first();
// or
$Categories->where("CategoryID", '=', $id)->first();
不能静态调用where
。签出类Illuminate'Support'Collection
。
编辑:
你只能用你尝试过的方式,在Eloquent模型上称之为静态。并且因为您已经获取了结果(进入Collection)。