Guest User

Untitled

a guest
Jun 24th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. <?php
  2.  
  3. $ids = array_unique([1,2,3,4,5, ...]);
  4.  
  5. // relation() is HasMany
  6.  
  7. // check if all $ids belong to this parent model:
  8. $parent_model->relation()->whereIn('id', $ids)->count() === count($ids)
  9.  
  10. // check if $ids match all of the children records:
  11. $parent_model->relation()->count() === count($ids)
  12. // if necessary check what's missing and where:
  13. $ids = collect($ids);
  14. $related_ids = $parent_model->relation()->pluck('id');
  15. $missing_input = $related_ids->diff($ids);
  16. $missing_in_db = $ids->diff($related_ids);
Add Comment
Please, Sign In to add comment