現在它將顯示帶有標簽 85 或 86 或 87 的 post_id。
如何僅顯示帶有標簽 85、86 和 87 的 post_id?
$values = DB::table('post_tag')
->whereIn('tag_id', [85, 86, 87])
->pluck('post_id');
這是表結構

uj5u.com熱心網友回復:
你可以在下面做這樣的事情
$values = DB::table('post_tag')
->where('tag_id', 85)
->where('tag_id', 86)
->where('tag_id', 87)
->pluck('post_id');
uj5u.com熱心網友回復:
在查詢末尾添加 toArray()
$values = DB::table('post_tag')->whereIn('tag_id', [85, 86, 87])->pluck('post_id')->toArray();
uj5u.com熱心網友回復:
你應該添加 groupBy('post_id')
$values = DB::table('post_tag')->whereIn('tag_id', [85, 86, 87])->groupBy('post_id')->pluck('post_id')->toArray();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/464634.html
