Created
June 24, 2018 03:52
-
-
Save jarektkaczyk/3eaff4ccd1966183c58d18d85def293f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment