Support the ongoing development of Laravel.io →
Database Eloquent Architecture
Last updated 2 years ago.
0

If using Eloquent this should work: Tag belongsToMany('Item') Item belongsToMany('Tag')

Item::whereHas('Tag', function($q) use ($ID) {
	foreach($ID as $ids) {
		$q->where('id', $ID);
	}
	
})->lists('id');

Otherwise maybe try:

$res = DB::table('item_tag');

foreach($ID as $uID){
	$res->where('tag_id', '=', $uID);
}

$ItemID = $res->lists('item_id');
Last updated 2 years ago.
0

allmyitjason said:

Otherwise maybe try:

$res = DB::table('item_tag');

foreach($ID as $uID){
  $res->where('tag_id', '=', $uID);
}

$ItemID = $res->lists('item_id');

I think it's the same as which wont work.

          $itemID = DB::table('item_tag')
                     ->where(function($query) use($ID)
                     {
                         foreach($ID as $uID){
                             $query->where('tag_id', '=', $uID);
                         }
                     })->lists('item_id');

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.