Now it will show post_id with tags 85 or 86 or 87.
How can I show only post_id with tags 85 and 86 and 87?
$values = DB::table('post_tag')
->whereIn('tag_id', [85, 86, 87])
->pluck('post_id');
This is the table structure
CodePudding user response:
You can do something like this below
$values = DB::table('post_tag')
->where('tag_id', 85)
->where('tag_id', 86)
->where('tag_id', 87)
->pluck('post_id');
CodePudding user response:
Add toArray() at the end of your query
$values = DB::table('post_tag')->whereIn('tag_id', [85, 86, 87])->pluck('post_id')->toArray();
CodePudding user response:
you should add groupBy('post_id')
$values = DB::table('post_tag')->whereIn('tag_id', [85, 86, 87])->groupBy('post_id')->pluck('post_id')->toArray();