public function scopeRestrictedBy($query, $restrictions) { if (!static::$respectRestrictions || count($restrictions) == 0) { return $query; } else { $restrictionIDs = $restrictions->lists('id')->toArray(); return $query->whereNotIn('id', Food::whereIn('id', DB::table('food_restriction')->whereIn('restriction_id', $restrictionIDs)->lists('food_id'))->lists('id')->toArray()); } }