8000 fixes args handling · laravel-enso/forms@43dca84 · GitHub
[go: up one dir, main page]

Skip to content

Commit 43dca84

Browse files
committed
fixes args handling
1 parent e03f809 commit 43dca84

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

src/Services/Form.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ public function edit(Model $model): Obj
5555
return $this->template;
5656
}
5757

58-
public function actions(string | array $actions): self
58+
public function actions($actions): self
5959
{
60-
$this->template->set('actions', new Obj($this->args($actions)));
60+
$args = Obj::wrap(is_string($actions) ? func_get_args() : $actions);
61+
62+
$this->template->set('actions', new Obj($args));
6163

6264
return $this;
6365
}
@@ -123,23 +125,23 @@ public function columns(string $field, int $value): self
123125
return $this;
124126
}
125127

126-
public function hide(string | array $fields): self
128+
public function hide($fields): self
127129
{
128-
$this->collection($fields)
130+
Collection::wrap(is_string($fields) ? func_get_args() : $fields)
129131
->each(fn ($field) => $this->field($field)
130132
->get('meta')->set('hidden', true));
131133

132134
return $this;
133135
}
134136

135-
public function hideSection(string | array $fields): self
137+
public function hideSection($fields): self
136138
{
137139
$this->sectionVisibility($fields, $hidden = true);
138140

139141
return $this;
140142
}
141143

142-
public function showSection(string | array $fields): self
144+
public function showSection($fields): self
143145
{
144146
$this->sectionVisibility($fields, $hidden = false);
145147

@@ -160,27 +162,27 @@ public function showTab($tabs): self
160162
return $this;
161163
}
162164

163-
public function show(string | array $fields): self
165+
public function show($fields): self
164166
{
165-
$this->collection($fields)
167+
Collection::wrap(is_string($fields) ? func_get_args() : $fields)
166168
->each(fn ($field) => $this->field($field)
167169
->get('meta')->set('hidden', false));
168170

169171
return $this;
170172
}
171173

172-
public function disable(string | array $fields): self
174+
public function disable($fields): self
173175
{
174-
$this->collection($fields)
176+
Collection::wrap(is_string($fields) ? func_get_args() : $fields)
175177
->each(fn ($field) => $this->field($field)
176178
->get('meta')->set('disabled', true));
177179

178180
return $this;
179181
}
180182

181-
public function readonly(string | array $fields): self
183+
public function readonly($fields): self
182184
{
183-
$this->collection($fields)
185+
Collection::wrap(is_string($fields) ? func_get_args() : $fields)
184186
->each(fn ($field) => $this->field($field)
185187
->get('meta')->set('readonly', true));
186188

@@ -226,17 +228,17 @@ public function labels(bool $labels): self
226228
return $this;
227229
}
228230

229-
public function sectionVisibility(string | array $fields, bool $hidden): self
231+
public function sectionVisibility($fields, bool $hidden): self
230232
{
231-
$this->collection($fields)
233+
Collection::wrap(is_string($fields) ? func_get_args() : $fields)
232234
->each(fn ($field) => $this->section($field)->put('hidden', $hidden));
233235

234236
return $this;
235237
}
236238

237-
public function tabVisibility(string | array $tabs, bool $hidden): self
239+
public function tabVisibility($tabs, bool $hidden): self
238240
{
239-
$tabs = $this->collection($tabs);
241+
$tabs = Collection::wrap(is_string($tabs) ? func_get_args() : $tabs);
240242

241243
$this->template->get('sections')->each(fn ($section) => $tabs->when(
242244
$tabs->contains($section->get('tab')),
@@ -310,14 +312,4 @@ private function needsValidation(): bool
310312

311313
return in_array($validations, [App::environment(), 'always']);
312314
}
313-
314-
private function collection(string | array $fields): Collection
315-
{
316-
return new Collection($this->args($fields));
317-
}
318-
319-
private function args(string | array $args): array
320-
{
321-
return is_string($args) ? func_get_args() : $args;
322-
}
323315
}

0 commit comments

Comments
 (0)
0