laravel - 控制器中的序列码问题
问题描述
$trendtag
仅代码有效。但是,如果我想加载帖子,它不会得到帖子。
如果我运行dd($tagIdArray)
,我会得到id
标签的 's。但是下面的代码没有任何功能。如果我不使用 $trendtags,或者只是这样,它可以工作:
$trendtags = Taggable::take(3)
->with('tag')
->get();
但是我怎样才能找到过去 48 小时内最常用的标签?
还有其他方法吗?
$trendtags = Taggable::whereDate('created_at', '>=', now()->subHours(48))
->groupBy('tag_id')
->orderByRaw('count(tag_id) DESC')
->take(3)
->with('tag')
->get();
$tagIdArray = $trendtags->pluck('id')->all();
$article = Article::with('comments', 'tags')
->whereIn('privacy', [1, 2])
->where('status', 1)
->whereHas('tags', function($query) use ($tagIdArray) {
$query->whereIn('id', $tagIdArray);
}, '>=', count($tagIdArray))
->latest()
->paginate(15);
解决方案
推荐阅读
- javascript - 将来自 firestore 查询的数据添加到数组对象并将它们映射到 Picker react native
- tinymce-5 - TinyMCE 如何支持从 Word 粘贴的内容中的分页符
- python-3.x - 当标签不在本体中但可以在 URI 中找到时,从 owl 本体中提取标签
- nestjs - 将 nestjs DI 与类验证器一起使用
- android - 如何在复选框上使用边距,以便它们彼此位于
- postgresql - 使用 PostgreSQL select into 获取多列时出现问题
- sap-ase - 如何在 Sybase DB 中列出分配给他们的用户和角色
- java - 如何重新运行静态整数数组?
- reactjs - 值被重置但输入不是?
- ruby - 登录后在 ruby 中访问路由