現在我已經得到了這個在我Settings.php
模型:Laravel查詢構建器返回的對象,而不是建設者
public function scopeFromCache($query)
{
\Cache::rememberForever('settings', function() use ($query) {
return $query->first();
})->first();
}
然後在boot
方法從我AppServiceProvider
我這樣做:
$settings = Settings::fromCache()->first();
是有可能得到如下設置:
$settings = Settings::fromCache();
因此,而不是返回query builder
返回對象?
但是,不是說'first()'方法正在做什麼,從集合而不是查詢生成器返回第一個對象?你爲什麼不想這樣做? – codedge