我找不到有关的信息:如何从高速缓存Laravel 5中选择复杂。
我有疑问:
$companys = Company::with(['comments' => function ($query) {
$query->where('status', '=', 'done');
}])->withCount('comments')->has('comments')->inRandomOrder()->paginate(8);
我需要缓存此查询。
我希望快速缓存所有带有注释的公司,并在进行查询后进行缓存以获取具有计数注释和分页的随机公司。
像这样的东西:
$cache_companys = Cache::remember('companys', 30, function () {
return Company::with('comments')->get();
});
并且从$ cache公司获得我的公司的分页。
我尝试过:
$companys = Cache::remember('companys', 30, function () {
return Company::with(['comments' => function ($query) {
$query->where('status', '=', 'done');
}])->withCount('comments')->has('comments')->inRandomOrder()->paginate(8);
});
但在这种情况下,每一页的分页都是同一家公司。
请帮帮我。
谢谢。
解决我的问题:
$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$companys = Cache::remember('companys-'.$currentPage, 30, function () {
return Company::with(['comments' => function ($query) {
$query->where('status', '=', 'done');
}])->withCount('comments')->has('comments')->inRandomOrder()->paginate(8);
});