From 4bff9cf53d1a1adfb6c956d2049e62c2caa8897d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Fri, 29 Dec 2023 09:32:45 +0100 Subject: [PATCH] model url fix --- src/Fields/Relation.php | 2 +- src/Fields/Repeater.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Fields/Relation.php b/src/Fields/Relation.php index beaf0cd4..1666910e 100644 --- a/src/Fields/Relation.php +++ b/src/Fields/Relation.php @@ -521,7 +521,7 @@ public function mapRelated(Request $request, Model $model, Model $related): arra */ public function modelUrl(Model $model): string { - return str_replace('{resourceModel}', $model->getKey(), $this->getUri()); + return str_replace('{resourceModel}', $model->exists ? $model->getKey() : 'create', $this->getUri()); } /** diff --git a/src/Fields/Repeater.php b/src/Fields/Repeater.php index c19a50ec..dff93517 100644 --- a/src/Fields/Repeater.php +++ b/src/Fields/Repeater.php @@ -111,7 +111,7 @@ public function withFields(Closure $callback): static { $this->optionFieldsResolver = function (Request $request, Model $model, Model $tmpModel) use ($callback): Fields { $fields = new Fields([ - Hidden::make(__('Key'), '_key'), + Hidden::make(__('Key'), '_key') ]); $fields->register(call_user_func_array($callback, [$request, $model, $tmpModel])); @@ -185,7 +185,7 @@ public function buildOption(Request $request, Model $model): array */ public function modelUrl(Model $model): string { - return str_replace('{resourceModel}', $model->getKey(), $this->getUri()); + return str_replace('{resourceModel}', $model->exists ? $model->getKey() : 'create', $this->getUri()); } /**