diff --git a/resources/views/base/form/form.blade.php b/resources/views/base/form/form.blade.php index c173fed7f..6c121cf42 100644 --- a/resources/views/base/form/form.blade.php +++ b/resources/views/base/form/form.blade.php @@ -35,7 +35,10 @@ class="py-4 px-6 block focus:outline-none text-purple"> @foreach($resource->formComponents() as $field) @if($field instanceof \Leeto\MoonShine\Decorations\Decoration) {{ $resource->renderDecoration($field, $item) }} - @elseif($field instanceof \Leeto\MoonShine\Fields\Field && $field->showOnForm) + @elseif($field instanceof \Leeto\MoonShine\Fields\Field + && $field->showOnForm + && ($item->exists ? $field->showOnUpdateForm : $field->showOnCreateForm) + ) {{ $resource->renderField($field, $item) }} diff --git a/resources/views/decorations/tab.blade.php b/resources/views/decorations/tab.blade.php index 50459a49d..b3bcdbb62 100644 --- a/resources/views/decorations/tab.blade.php +++ b/resources/views/decorations/tab.blade.php @@ -2,10 +2,13 @@ @foreach($decoration->fields() as $field) @if($field instanceof \Leeto\MoonShine\Decorations\Decoration) {{ $resource->renderDecoration($field, $item) }} - @elseif($field instanceof \Leeto\MoonShine\Fields\Field && $field->showOnForm) + @elseif($field instanceof \Leeto\MoonShine\Fields\Field + && $field->showOnForm + && ($item->exists ? $field->showOnUpdateForm : $field->showOnCreateForm) + ) {{ $resource->renderField($field, $item) }} @endif @endforeach - \ No newline at end of file + diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 06fd38e5d..5e9456d87 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -40,6 +40,10 @@ abstract class Field implements HtmlViewable, HasAssets, HasExportViewValue, Has public bool $showOnForm = true; + public bool $showOnCreateForm = true; + + public bool $showOnUpdateForm = true; + protected Field|null $parent = null; protected string $hint = ''; @@ -107,6 +111,58 @@ public function hideOnForm(mixed $condition = null): static return $this; } + /** + * Set field as show on create page, based on condition + * + * @param mixed $condition + * @return $this + */ + public function showOnCreate(mixed $condition = null): static + { + $this->showOnCreateForm = Condition::boolean($condition, true); + + return $this; + } + + /** + * Set field as hidden on create page, based on condition + * + * @param mixed $condition + * @return $this + */ + public function hideOnCreate(mixed $condition = null): static + { + $this->showOnCreateForm = Condition::boolean($condition, false); + + return $this; + } + + /** + * Set field as show on update page, based on condition + * + * @param mixed $condition + * @return $this + */ + public function showOnUpdate(mixed $condition = null): static + { + $this->showOnUpdateForm = Condition::boolean($condition, true); + + return $this; + } + + /** + * Set field as hidden on update page, based on condition + * + * @param mixed $condition + * @return $this + */ + public function hideOnUpdate(mixed $condition = null): static + { + $this->showOnUpdateForm = Condition::boolean($condition, false); + + return $this; + } + /** * Set field as visible in export report, based on condition *