Skip to content

Commit b494695

Browse files
Merge pull request #55 from kirschbaum-development/bugfix/date-time-display
Fix Date Time display
2 parents cd435dd + 49dcd65 commit b494695

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/NovaInlineRelationship.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Carbon\Carbon;
77
use App\Nova\Resource;
88
use Laravel\Nova\Nova;
9+
use Illuminate\Support\Arr;
910
use Illuminate\Support\Str;
1011
use Laravel\Nova\Fields\ID;
1112
use Laravel\Nova\Fields\File;
@@ -286,15 +287,21 @@ protected function modelIds()
286287
* @param array $item
287288
* @param $attrib
288289
* @param null $value
290+
* @param null|mixed $resource
289291
*
290292
* @return array
291293
*/
292-
protected function setMetaFromClass(array $item, $attrib, $value = null)
294+
protected function setMetaFromClass(array $item, $attrib, $value = null, $resource = null)
293295
{
294296
$attrs = ['name' => $attrib, 'attribute' => $attrib];
295297

296298
/** @var Field $class */
297299
$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+
298305
$class->value = $value !== null ? $value : '';
299306

300307
if (! empty($item['options']) && is_array($item['options'])) {
@@ -460,13 +467,17 @@ protected function getPropertiesFromFields(Collection $fields): Collection
460467
protected function updateFieldValue($resource, $attribute, Collection $properties): void
461468
{
462469
if ($this->isSingularRelationship($resource, $attribute)) {
463-
$this->value = collect($this->value ? [$this->value] : []);
470+
$this->value = collect(Arr::wrap($this->value));
464471
}
465472

466473
$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();
470481
});
471482
}
472483

0 commit comments

Comments
 (0)