Skip to content

Commit 738eb68

Browse files
committed
Early return and type fix
1 parent 79b3379 commit 738eb68

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ The fillUsing method allows you to alter the data or store the data on a differe
170170

171171
```php
172172
Flexible::make('Content', 'content')
173-
->fillUsing(function ($request, $model, $attribute, $requestAttribte) {
174-
$value = $request->{$requestAttribte};
173+
->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
174+
$value = $request->{$requestAttribute};
175175

176176
$model->{$attribute} = $value;
177177
})

src/Flexible.php

+14-10
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,17 @@ public function resolve($resource, $attribute = null)
241241
{
242242
$attribute = $attribute ?? $this->attribute;
243243

244-
if (! $this->resolveCallback) {
245-
$this->registerOriginModel($resource);
246-
247-
$this->buildGroups($resource, $attribute);
248-
249-
$this->value = $this->resolveGroups($this->groups);
250-
} elseif (is_callable($this->resolveCallback)) {
244+
if ($this->resolveCallback && is_callable($this->resolveCallback)) {
251245
$this->value = call_user_func($this->resolveCallback, $this, $resource, $attribute);
246+
247+
return;
252248
}
249+
250+
$this->registerOriginModel($resource);
251+
252+
$this->buildGroups($resource, $attribute);
253+
254+
$this->value = $this->resolveGroups($this->groups);
253255
}
254256

255257
/**
@@ -263,11 +265,13 @@ public function resolveForDisplay($resource, $attribute = null)
263265
{
264266
$attribute = $attribute ?? $this->attribute;
265267

266-
if (! $this->displayCallback) {
267-
$this->resolve($resource, $attribute);
268-
} elseif (is_callable($this->displayCallback)) {
268+
if ($this->displayCallback && is_callable($this->displayCallback)) {
269269
$this->value = call_user_func($this->displayCallback, $this, $resource, $attribute);
270+
271+
return;
270272
}
273+
274+
$this->resolve($resource, $attribute);
271275
}
272276

273277
/**

0 commit comments

Comments
 (0)