Skip to content

Commit e8f5601

Browse files
committed
wip
1 parent 90f34bf commit e8f5601

File tree

1 file changed

+124
-3
lines changed

1 file changed

+124
-3
lines changed

fields.md

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ $field->max('2024-01-01');
227227
$field->max(now()->addDays(7));
228228
```
229229

230+
### Dropdown
231+
232+
The `Dropdown` field is turbo-charded version of the [`Select`](#select) field. You may checkout its documentation.
233+
234+
```php
235+
$field = Dropdown::make(__('Tags'), 'tags')
236+
->options([
237+
'bug' => 'Bug',
238+
'info' => 'Info',
239+
'question' => 'Question',
240+
]);
241+
```
242+
230243
### Editor
231244

232245
The `Editor` field is typically a handler for `text` model attributes (HTML). The `Editor` field is a [Tiptap](https://tiptap.dev/product/editor) editor combined with [alpine](https://alpinejs.dev/):
@@ -263,20 +276,116 @@ You can also apply modifiers on a `Editor` field:
263276
$field->height('300px');
264277
```
265278

266-
### File
279+
### Email
280+
281+
The `Email` field is typically a handler for `email` model attributes:
282+
283+
```php
284+
$field = Email::make(__('Billing Email'), 'billing_email');
285+
```
286+
287+
> You may use the `email` validation rule for this field. By default no rules attached.
288+
289+
### Fieldset
290+
291+
The `Fieldset` field a handler for grouped sub-fields. Also, it renders its fields into a `<fieldset>` HTML element:
292+
293+
```php
294+
$group = Fieldset::make(__('Billing Fields'), 'billing')
295+
->withFields(static function (): array {
296+
return [
297+
Text::make(__('Name'), 'billing_name'),
298+
Email::make(__('Email', 'billing_email')),
299+
];
300+
});
301+
```
302+
303+
### Hidden
304+
305+
The `Hidden` field is eqvivalent to a simple `Field` instance, however it automatically gets a `type="hidden"` HTML attribute, that makes it uneditable:
306+
307+
```php
308+
$field = Hidden::make(__('Token'), 'token')
309+
->default(fn (): string => Str::uuid());
310+
```
267311

268312
### ID
269313

270-
### Media
314+
The `ID` field is typically a handler for the model's primary key. It can be an incremental numeric ID or a UUID as well.
315+
316+
```php
317+
$field = ID::make();
318+
```
271319

272320
### Number
273321

322+
The `Number` field is typically a handler for `numeric` model attributes:
323+
324+
```php
325+
$field = Number::make(__('Age'), 'age');
326+
```
327+
328+
You can also apply modifiers on a text field:
329+
330+
```php
331+
// Adds the "size" HTML input attribute
332+
$field->size(40);
333+
334+
// Adds the "min" HTML input attribute
335+
$field->min(40);
336+
337+
// Adds the "max" HTML input attribute
338+
$field->max(40);
339+
340+
// Adds the "step" HTML input attribute
341+
$field->step(1);
342+
```
343+
274344
### Radio
275345

346+
The `Radio` field is similar to [`Checkbox`](#checkbox), however only single values are allowed, unlike in the case of `Checkbox`, where array of values are being stored:
347+
348+
```php
349+
$field = Radio::make(__('Role'), 'role')
350+
->options([
351+
'admin' => 'Admin',
352+
'editor' => 'Editor',
353+
'member' => 'Member',
354+
]);
355+
```
356+
357+
You may also pass a `Closure` to customize the resolution logic of the options:
358+
359+
```php
360+
use App\Category;
361+
use Illuminate\Database\Eloquent\Model;
362+
use Illuminate\Http\Request;
363+
364+
$field = Radio::make(__('Category'), 'category')
365+
->options(static function (Request $request, Model $model): array {
366+
return match (true) {
367+
$request->user()->isAdmin() => Category::query()->pluck('name', 'id')->all(),
368+
default => $request->user()->categories()->pluck('name', 'id')->all(),
369+
};
370+
});
371+
```
372+
276373
### Range
277374

375+
The `Range` field is typically a handler for `numeric` model attributes:
376+
377+
```php
378+
$field = Range::make(__('Points'), 'points')
379+
->min(0)
380+
->max(10);
381+
```
382+
383+
### Repeater
384+
278385
### Select
279386

387+
### Slug
388+
280389
### Tag
281390

282391
### Text
@@ -287,7 +396,7 @@ The `Text` field is typically a handler for `string` model attributes:
287396
$field = Text::make(__('Title'), 'title');
288397
```
289398

290-
You can also apply modifiers on a text field:
399+
You can also apply modifiers on `Text` field:
291400

292401
```php
293402
// Adds the "size" HTML input attribute
@@ -318,6 +427,8 @@ $field->rows(20);
318427
$field->cols(100);
319428
```
320429

430+
### URL
431+
321432
### Relation Fields
322433

323434
Relation fields are representing Eloquent relation definitions on the resource models. Relation fields are highly customizable and provide a nice and detailed API.
@@ -343,3 +454,13 @@ $field = BelongsTo::make(__('Author'), 'author');
343454
#### MorphOne
344455

345456
#### MorphToMany
457+
458+
#### File
459+
460+
The `File` field is typically a handler for `json` model attributes (array of values):
461+
462+
#### Media
463+
464+
#### Meta
465+
466+
### Computed Fields

0 commit comments

Comments
 (0)