Created
June 24, 2018 03:52
-
-
Save jarektkaczyk/3eaff4ccd1966183c58d18d85def293f to your computer and use it in GitHub Desktop.
Revisions
-
jarektkaczyk revised this gist
Jun 24, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <?php $ids = array_unique([1,2,3,4,5, ...]); // relation() is HasMany -
jarektkaczyk created this gist
Jun 24, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ $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);