Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ids = array_unique([1,2,3,4,5, ...]);
- // relation() is HasMany
- // check if all $ids belong to this parent model:
- $parent_model->relation()->whereIn('id', $ids)->count() === count($ids)
- // check if $ids match all of the children records:
- $parent_model->relation()->count() === count($ids)
- // if necessary check what's missing and where:
- $ids = collect($ids);
- $related_ids = $parent_model->relation()->pluck('id');
- $missing_input = $related_ids->diff($ids);
- $missing_in_db = $ids->diff($related_ids);
Add Comment
Please, Sign In to add comment