updateOrCreate( [ 'subject_type' => $subject->getMorphClass(), 'subject_id' => $subject->getKey(), 'editorial_dimension_value_id' => $value->id, ], ['origin' => $origin], ); } /** * @param list $valueIds */ public function matches(Model $subject, array $valueIds): bool { if ($valueIds === []) { return true; } $assigned = IdentityDimensionValue::query() ->where('subject_type', $subject->getMorphClass()) ->where('subject_id', $subject->getKey()) ->pluck('editorial_dimension_value_id') ->all(); $wanted = EditorialDimensionValue::query()->whereIn('id', $valueIds)->get()->groupBy('editorial_dimension_id'); if ($wanted->isEmpty()) { return false; } foreach ($wanted as $group) { $ids = $group->pluck('id')->all(); if (array_intersect($ids, $assigned) === []) { return false; } } return true; } }