You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChecksForeignKeyConstraints.php 388B

123456789101112131415161718
  1. <?php
  2. namespace App\Traits;
  3. trait ChecksForeignKeyConstraints
  4. {
  5. public static function isForeignKeyUsed($field, $value, array $models): bool
  6. {
  7. foreach ($models as $model) {
  8. $modelInstance = resolve($model);
  9. if ($modelInstance->where($field, $value)->exists()) {
  10. return true;
  11. }
  12. }
  13. return false;
  14. }
  15. }