Skip to content

Commit 3c49e2b

Browse files
committed
wip
1 parent 4eed9e1 commit 3c49e2b

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/Fields/Field.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,16 @@ public function format(?Closure $callback = null): static
516516
/**
517517
* Format the value.
518518
*/
519-
public function resolveFormat(Request $request, Model $model): mixed
519+
public function resolveFormat(Request $request, Model $model): ?string
520520
{
521521
$value = $this->resolveValue($request, $model);
522522

523523
if (is_null($this->formatResolver)) {
524-
return is_array($value) ? json_encode($value) : $value;
524+
return match (true) {
525+
is_array($value) => json_encode($value),
526+
is_null($value) => $value,
527+
default => (string) $value,
528+
};
525529
}
526530

527531
return call_user_func_array($this->formatResolver, [$request, $model, $value]);

src/Fields/Relation.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ abstract class Relation extends Field implements Form
9191
*/
9292
protected ?Closure $aggregateResolver = null;
9393

94-
/**
95-
* Determine whether the relation values are aggregated.
96-
*/
97-
protected bool $aggregated = false;
98-
9994
/**
10095
* The option group resolver.
10196
*/
@@ -390,7 +385,7 @@ public function resolveDisplay(Model $related): ?string
390385
*/
391386
public function getValue(Model $model): mixed
392387
{
393-
if ($this->aggregated) {
388+
if (is_callable($this->aggregateResolver)) {
394389
return parent::getValue($model);
395390
}
396391

@@ -412,11 +407,14 @@ public function resolveFormat(Request $request, Model $model): ?string
412407
$this->formatResolver = function (Request $request, Model $model): mixed {
413408
$default = $this->getValue($model);
414409

415-
if ($this->aggregated) {
416-
return $default;
410+
if (is_callable($this->aggregateResolver)) {
411+
return (string) $default;
417412
}
418413

419-
return Collection::wrap($default)->map(fn (Model $related): ?string => $this->formatRelated($request, $model, $related))->filter()->join(', ');
414+
return Collection::wrap($default)
415+
->map(fn (Model $related): ?string => $this->formatRelated($request, $model, $related))
416+
->filter()
417+
->join(', ');
420418
};
421419
}
422420

@@ -540,8 +538,6 @@ public function aggregate(string $fn = 'count', string $column = '*'): static
540538
$column === '*' ? '' : sprintf('_%s', $column)
541539
));
542540

543-
$this->aggregated = true;
544-
545541
return $query->withAggregate($this->getRelationName(), $column, $fn);
546542
};
547543

src/Fields/Repeater.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ public function buildOption(Request $request, Model $model): array
209209
*/
210210
public function modelUrl(Model $model): string
211211
{
212-
return str_replace('{resourceModel}', $model->exists ? (string) $model->getKey() : 'create', $this->getUri());
212+
$key = $model->exists ? (string) $model->getKey() : 'create';
213+
214+
return str_replace('{resourceModel}', $key, $this->getUri());
213215
}
214216

215217
/**

0 commit comments

Comments
 (0)