Skip to content

Commit 10f4f1c

Browse files
committed
Add violatedLazyLoading handler
1 parent 3ec6377 commit 10f4f1c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public function getRelationValue($key)
439439
}
440440

441441
if ($this->preventsLazyLoading) {
442-
throw new LazyLoadingViolationException($this, $key);
442+
$this->violatedLazyLoading($key);
443443
}
444444

445445
// If the "attribute" exists as a method on the model, we will just assume
@@ -460,6 +460,17 @@ public function isRelation($key)
460460
(static::$relationResolvers[get_class($this)][$key] ?? null);
461461
}
462462

463+
/**
464+
* Handle a lazy loading violation, for example by throwing an exception.
465+
*
466+
* @param string $key
467+
* @return void
468+
*/
469+
protected function violatedLazyLoading($key)
470+
{
471+
throw new LazyLoadingViolationException($this, $key);
472+
}
473+
463474
/**
464475
* Get a relationship value from a method.
465476
*

0 commit comments

Comments
 (0)