|
6 | 6 | use Carbon\Carbon; |
7 | 7 | use App\Nova\Resource; |
8 | 8 | use Laravel\Nova\Nova; |
| 9 | +use Illuminate\Support\Arr; |
9 | 10 | use Illuminate\Support\Str; |
10 | 11 | use Laravel\Nova\Fields\ID; |
11 | 12 | use Laravel\Nova\Fields\File; |
@@ -286,15 +287,21 @@ protected function modelIds() |
286 | 287 | * @param array $item |
287 | 288 | * @param $attrib |
288 | 289 | * @param null $value |
| 290 | + * @param null|mixed $resource |
289 | 291 | * |
290 | 292 | * @return array |
291 | 293 | */ |
292 | | - protected function setMetaFromClass(array $item, $attrib, $value = null) |
| 294 | + protected function setMetaFromClass(array $item, $attrib, $value = null, $resource = null) |
293 | 295 | { |
294 | 296 | $attrs = ['name' => $attrib, 'attribute' => $attrib]; |
295 | 297 |
|
296 | 298 | /** @var Field $class */ |
297 | 299 | $class = app($item['component'], $attrs); |
| 300 | + |
| 301 | + if (isset($value) && is_callable($class->resolveCallback)) { |
| 302 | + $value = call_user_func($class->resolveCallback, $value, $resource, $attrib); |
| 303 | + } |
| 304 | + |
298 | 305 | $class->value = $value !== null ? $value : ''; |
299 | 306 |
|
300 | 307 | if (! empty($item['options']) && is_array($item['options'])) { |
@@ -460,13 +467,17 @@ protected function getPropertiesFromFields(Collection $fields): Collection |
460 | 467 | protected function updateFieldValue($resource, $attribute, Collection $properties): void |
461 | 468 | { |
462 | 469 | if ($this->isSingularRelationship($resource, $attribute)) { |
463 | | - $this->value = collect($this->value ? [$this->value] : []); |
| 470 | + $this->value = collect(Arr::wrap($this->value)); |
464 | 471 | } |
465 | 472 |
|
466 | 473 | $this->value = $this->value->map(function ($items) use ($properties) { |
467 | | - return collect($items)->map(function ($value, $key) use ($properties) { |
468 | | - return $properties->has($key) ? $this->setMetaFromClass($properties->get($key), $key, $value) : null; |
469 | | - })->filter(); |
| 474 | + return collect($items) |
| 475 | + ->map(function ($value, $key) use ($properties, $items) { |
| 476 | + return $properties->has($key) |
| 477 | + ? $this->setMetaFromClass($properties->get($key), $key, $items->{$key} ?? $value) |
| 478 | + : null; |
| 479 | + }) |
| 480 | + ->filter(); |
470 | 481 | }); |
471 | 482 | } |
472 | 483 |
|
|
0 commit comments