You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You may also pass a `Closure` to customize the resolution logic of the options, see the [`Select`](#select) field.
344
+
345
+
### Range
346
+
347
+
The `Range` field is typically a handler for `numeric` model attributes:
348
+
349
+
```php
350
+
$field = Range::make(__('Points'), 'points')
351
+
->min(0)
352
+
->max(10);
353
+
```
354
+
355
+
### Repeater
356
+
357
+
The `Repeater` field similar to the [`Fieldset`](#fieldset) field, however the sub-fields are repeatable:
358
+
359
+
```php
360
+
$field = Repeater::make(__('Books'), 'books')
361
+
->withFields(static function (): array {
362
+
return [
363
+
Text::make(__('Author'), 'author'),
364
+
Text::make('ISBN'),
365
+
];
366
+
});
367
+
```
368
+
369
+
You may also set a maximum number of repeatable elements using the `max` method:
370
+
371
+
```php
372
+
$field->max(4);
373
+
```
374
+
375
+
### Select
376
+
377
+
The `Select` field is similar to the [`Checkbox`](#checkbox), [`Dropdown`](#dropdown) and [`Radio`](#radio) fields, in fact the `Select` field is their parent class:
378
+
379
+
```php
380
+
$field = Select::make(__('Tags'), 'tags')
381
+
->options([
382
+
'bug' => 'Bug',
383
+
'info' => 'Info',
384
+
'question' => 'Question',
385
+
]);
386
+
```
387
+
388
+
You may make the field to `nullable` which means an extra empty option is available in the options:
389
+
390
+
```php
391
+
$field->nullable();
392
+
393
+
// or
394
+
395
+
$field->nullable(false);
396
+
```
397
+
398
+
You can also apply modifiers on `Select` field:
399
+
400
+
```php
401
+
// Adds the "size" HTML input attribute
402
+
$field->size(10);
403
+
404
+
// Adds the "multiple" HTML input attribute
405
+
$field->multiple();
406
+
// or
407
+
$field->multiple(false);
408
+
```
409
+
357
410
You may also pass a `Closure` to customize the resolution logic of the options:
358
411
359
412
```php
360
413
use App\Category;
361
414
use Illuminate\Database\Eloquent\Model;
362
415
use Illuminate\Http\Request;
363
416
364
-
$field = Radio::make(__('Category'), 'category')
417
+
$field = Select::make(__('Category'), 'category')
365
418
->options(static function (Request $request, Model $model): array {
The `Range` field is typically a handler for `numeric` model attributes:
428
+
The `Slug` field is typically a handler for auto-generating URL friendly values of specified model attributes:
376
429
377
430
```php
378
-
$field = Range::make(__('Points'), 'points')
379
-
->min(0)
380
-
->max(10);
431
+
$field = Slug::make(__('Slug'), 'slug')
432
+
->from(['name']);
381
433
```
382
434
383
-
### Repeater
435
+
You may also want to have unique slugs, which means when a slug is already exists in the databse table, the new slug will get an incremented numeric suffix to avoid conflicts:
384
436
385
-
### Select
437
+
```php
438
+
$field->unique();
386
439
387
-
### Slug
440
+
// unique-slug
441
+
// unique-slug-1
442
+
// unique-slug-2
443
+
// etc...
444
+
```
445
+
446
+
You may also want to customize the slug separator:
447
+
448
+
```php
449
+
$field->separator('_');
450
+
```
451
+
452
+
> The default slug separator is `-`.
453
+
454
+
You may also want to completely customize the slug generation logic:
455
+
456
+
```php
457
+
use Illuminate\Database\Eloquent\Model;
458
+
use Illuminate\Http\Request;
459
+
use Illuminate\Support\Str;
460
+
461
+
$field->generateUsing(static function (Request $request, Model $model, string $value): string {
462
+
return sprintf('%s-%s', $value, Str::random(5));
463
+
});
464
+
```
465
+
466
+
By default the `Slug` field is generating slug only when creating the model. If you want to run the generation logic when the model is being updated as well, you may call the `always` method:
0 commit comments