Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 26, 2021
1 parent fd3ab0c commit c986e12
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
14 changes: 6 additions & 8 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public function getRelationValue($key)
}

if ($this->preventsLazyLoading) {
$this->violatedLazyLoading($key);
$this->handleLazyLoadingViolation($key);
}

// If the "attribute" exists as a method on the model, we will just assume
Expand All @@ -461,17 +461,15 @@ public function isRelation($key)
}

/**
* Handle a lazy loading violation, for example by throwing an exception.
* Handle a lazy loading violation.
*
* @param string $key
* @return void
* @return mixed
*/
protected function violatedLazyLoading($key)
protected function handleLazyLoadingViolation($key)
{
if (isset(static::$violatedLazyLoadingCallback)) {
call_user_func(static::$violatedLazyLoadingCallback, $this, $key);

return;
if (isset(static::$lazyLoadingViolationCallback)) {
return call_user_func(static::$lazyLoadingViolationCallback, $this, $key);
}

throw new LazyLoadingViolationException($this, $key);
Expand Down
9 changes: 5 additions & 4 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ abstract class Model implements Arrayable, ArrayAccess, Jsonable, JsonSerializab
protected static $modelsShouldPreventLazyLoading = false;

/**
* The callback that is responsible for handing lazy loading violations.
* The callback that is responsible for handling lazy loading violations.
*
* @var callable|null
*/
protected static $violatedLazyLoadingCallback;
protected static $lazyLoadingViolationCallback;

/**
* The name of the "created at" column.
Expand Down Expand Up @@ -368,11 +368,12 @@ public static function preventLazyLoading($value = true)
/**
* Register a callback that is responsible for handling lazy loading violations.
*
* @param callable $callback
* @param callable $callback
* @return void
*/
public static function handleLazyLoadingViolationUsing(callable $callback)
{
static::$violatedLazyLoadingCallback = $callback;
static::$lazyLoadingViolationCallback = $callback;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Database/EloquentStrictLoadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function modelTwos()
return $this->hasMany(EloquentStrictLoadingTestModel2::class, 'model_1_id');
}

protected function violatedLazyLoading($key)
protected function handleLazyLoadingViolation($key)
{
throw new \RuntimeException("Violated {$key}");
}
Expand Down

0 comments on commit c986e12

Please sign in to comment.