diff --git a/src/Fields/Boolean.php b/src/Fields/Boolean.php index 7c1a8c85..7fe4b5e4 100644 --- a/src/Fields/Boolean.php +++ b/src/Fields/Boolean.php @@ -2,6 +2,7 @@ namespace Cone\Root\Fields; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; class Boolean extends Field @@ -42,9 +43,9 @@ public function checked(bool $value = true): static /** * Create a new method. */ - public function resolveValue(Request $request): mixed + public function resolveValue(Request $request, Model $model): mixed { - $value = parent::resolveValue($request); + $value = parent::resolveValue($request, $model); $this->checked(filter_var($value, FILTER_VALIDATE_BOOL)); diff --git a/src/Fields/Fieldset.php b/src/Fields/Fieldset.php index f5a33a25..694be62d 100644 --- a/src/Fields/Fieldset.php +++ b/src/Fields/Fieldset.php @@ -3,6 +3,7 @@ namespace Cone\Root\Fields; use Cone\Root\Traits\ResolvesFields; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; @@ -28,7 +29,7 @@ protected function resolveField(Request $request, Field $field): void /** * {@inheritdoc} */ - public function persist(Request $request, mixed $value): void + public function persist(Request $request, Model $model, mixed $value): void { $this->resolveFields($request)->each(static function (Field $field) use ($request): void { $field->persist($request, $field->getValueForHydrate($request)); @@ -38,7 +39,7 @@ public function persist(Request $request, mixed $value): void /** * {@inheritdoc} */ - public function resolveHydrate(Request $request, mixed $value): void + public function resolveHydrate(Request $request, Model $model, mixed $value): void { $this->resolveFields($request)->each(static function (Field $field) use ($request): void { $field->resolveHydrate($request, $field->getValueForHydrate($request)); @@ -72,10 +73,10 @@ public function toArray(): array /** * {@inheritdoc} */ - public function toValidate(Request $request): array + public function toValidate(Request $request, Model $model): array { return array_merge( - parent::toValidate($request), + parent::toValidate($request, $model), $this->resolveFields($request)->mapToValidate($request) ); } diff --git a/src/Fields/HasOneOrMany.php b/src/Fields/HasOneOrMany.php index 1ed90202..01a6c894 100644 --- a/src/Fields/HasOneOrMany.php +++ b/src/Fields/HasOneOrMany.php @@ -25,7 +25,7 @@ public function persist(Request $request, Model $model, mixed $value): void $model->saved(function (Model $model) use ($request, $value): void { $relation = $this->getRelation($model); - $this->resolveHydrate($request, $value); + $this->resolveHydrate($request, $model, $value); $models = $model->getRelation($this->getRelationName()); @@ -44,7 +44,7 @@ public function resolveHydrate(Request $request, Model $model, mixed $value): vo { if (is_null($this->hydrateResolver)) { $this->hydrateResolver = function (Request $request, Model $model, mixed $value): void { - $related = $this->resolveRelatableQuery($request)->find($value); + $related = $this->resolveRelatableQuery($request, $model)->find($value); $model->setRelation($this->getRelationName(), $related); }; diff --git a/src/Fields/Meta.php b/src/Fields/Meta.php index b4ad846c..37e72eec 100644 --- a/src/Fields/Meta.php +++ b/src/Fields/Meta.php @@ -54,7 +54,7 @@ public function getRelationName(): string */ public function as(string $field, Closure $callback = null): static { - $this->field = new $field($this->form, $this->label, $this->getModelAttribute()); + $this->field = new $field($this->label, $this->getModelAttribute()); if (! is_null($callback)) { call_user_func_array($callback, [$this->field]);