diff --git a/src/Statable/Statable.php b/src/Statable/Statable.php index b5acdd2..0c759a3 100644 --- a/src/Statable/Statable.php +++ b/src/Statable/Statable.php @@ -37,7 +37,9 @@ protected function applyStates($states, $relation = null) $model = $relation ? $relation->getModel() : $this; foreach (Arr::wrap($states) as $state) { - if ($method = $this->modelHasState($model, $state)) { + $method = $this->getMethodName($state); + + if ($this->modelHasState($model, $method)) { $attributes[] = $this->expandAttributes( $model->$method() ); @@ -76,13 +78,11 @@ protected function getMethodName($state) */ protected function modelHasState($model, $state) { - return tap($this->getMethodName($state), function ($method) use ($model, $state) { - throw_unless( - method_exists($model, $method), - InvalidArgumentException::class, - sprintf('Unable to locate [%s] state for [%s].', $state, static::class) - ); - }); + return throw_unless( + method_exists($model, $state), + InvalidArgumentException::class, + sprintf('Unable to locate [%s] state for [%s].', $state, get_class($model)) + ); } /**