Fields overview
Every form field is a Blade component rendered through the Lte3 facade. The list of components, their arguments and default attributes lives in config/lte3.php under view.components.
Calling a field
Section titled “Calling a field”{!! Lte3::text('title', null, ['label' => 'Title', 'required' => true]) !!}Lte3is an alias ofFomvasss\Lte3\Facades\Lte, registered by the package service provider and by Laravel package discovery.- The call returns rendered HTML, so output it with
{!! !!}, not{{ }}. - Any method that is not defined on the class is looked up in
lte3.view.components.<name>. An unknown name throwsException: Lte3 method or component '<name>' not found!.
Positional arguments
Section titled “Positional arguments”Positional arguments are mapped, in order, to the component vars from the config. Missing arguments become null.
'text' => ['blade' => 'lte3::components.text', 'vars' => ['name', 'value', 'attrs'], 'default' => ['type' => 'text']],'select2' => ['blade' => 'lte3::components.select2', 'vars' => ['name', 'selected', 'options', 'attrs']],So Lte3::text('title', 'Hello', [...]) gives the view $name = 'title', $value = 'Hello', $attrs = [...], and Lte3::select2('status', 'new', $options, [...]) gives $name, $selected, $options, $attrs.
Every component view also receives:
$attrs— the componentdefaultarray from the config merged with the attrs you passed (yours win).$field_attrs— thelte3.view.field_attrslist.$model— the model of the currentLte3::formOpen(['model' => ...]), unless the component has its ownmodelvar that you passed.
Lte3::field() — array form
Section titled “Lte3::field() — array form”Lte3::field(array $params, array $params2 = []) renders a component described by one array. Useful when fields are built from data (settings pages, block definitions).
{!! Lte3::field([ 'type' => 'text', 'name' => 'nickname', 'value' => 'Nik', 'label' => 'Nickname', 'class' => 'some-class', 'data' => ['rr' => 'qq'],]) !!}
{!! Lte3::field([ 'type' => 'checkboxes', 'name' => 'rd', 'label' => 'Time of day', 'selected' => ['morning', 'day'], 'options' => ['night' => 'Night', 'morning' => 'Morning', 'day' => 'Day'],]) !!}typeis the component name from the config,textby default.- The two arrays are merged (
$params2wins). - For each component var except
attrs, the value is taken from the key with the same name (name,value,selected,options, …). Missing keys become an empty string, notnull. - The whole merged array is passed as
attrs, solabel,help,class, etc. go at the top level next toname.
Common attrs
Section titled “Common attrs”Most components read the attrs below. Exact support differs per component, so check the field page; link, the buttons, tableOptions, treeview and nestedset read only a few of them.
| Attr | Type | Default | Description |
|---|---|---|---|
label | string | studly name | Label HTML (printed unescaped). Str::studly($name) when not set: first_name becomes FirstName. '' hides the label. hidden shows a label only when it is set. |
help | string | - | Help text under the field (HTML, printed unescaped). |
class | string | - | Extra classes of the input element. |
class_wrap | string | - | Extra classes of the wrapping .form-group, e.g. grid classes. |
hidden_wrap | bool | false | Renders the wrapper with the hidden attribute. |
disabled | bool | false | Any truthy value adds disabled. |
readonly | bool | false | Any truthy value adds readonly (in components that support it). |
attrs | array | [] | Arbitrary HTML attributes printed on the input as key="value" (text, textarea, hidden, checkbox, checkboxes, radiogroup, select2, select2Tree, xEditable). |
data | array | [] | data-* attributes: ['compare-value' => 42] gives data-compare-value="42" (text, textarea, select2, radiogroup, treeview). |
default | mixed | - | Value used when nothing else provides one, see Value resolution. |
formatter | callable or class | - | Transforms the resolved value before rendering, see Formatter. |
field_attrs keys | mixed | - | placeholder, required, id, pattern, min, max, … printed as HTML attributes, see field_attrs. |
Validation errors are shown automatically: components check $errors for the field name (@error($name)) and print the message under the field; most of them also add is-invalid to the input.
Value resolution
Section titled “Value resolution”For components whose vars contain both name and value (hidden, text and its variants, slug, textarea, checkbox, colorpicker, range, xEditable, date/time pickers), the value is resolved in this order:
old($name)— the input flashed after a failed validation.request($name)— the current request query/body.- The
$valueargument, if notnull. - The form model, if
Lte3::formOpen(['model' => $model])is open:$model->getFormValue($key)when the model has such a method, otherwisedata_get($model, $key). - The
defaultattr (from your attrs, or from the componentdefault.defaultin the config).
Notes:
- The name is converted to a dot key for lookups:
meta[title]becomesmeta.title,tags[]becomestags, and.becomes_(as PHP does with request keys). - Steps 1 and 2 are skipped for the field named
_method. - If the
ConvertEmptyStringsToNullmiddleware is active, there are validation errors and bothold()and$valuearenull, the result isnull(a field the user cleared stays empty instead of showing the model value again). - When a form model is set, step 4 returns its value even if it is
null, sodefaultonly applies to forms without a model. - Components with other vars (
selected,path,items) resolve their values in their own views; see their pages.
getFormValue()
Section titled “getFormValue()”Define getFormValue(string $key) on a model to control what the form shows, e.g. for casts, translations or relations:
public function getFormValue($key){ return match ($key) { 'tags' => $this->tags->pluck('id')->all(), default => data_get($this, $key), };}Formatter
Section titled “Formatter”formatter changes the resolved value before it is passed to the view. It is applied only to components with a value var and only when given in the call attrs (not in the config default).
{!! Lte3::text('formatter', null, [ 'default' => 'some example formatter', 'formatter' => fn ($value) => \Illuminate\Support\Str::upper($value), // 'formatter' => 'some_upper_helper', // 'formatter' => \App\Formatters\UpperFormatter::class,]) !!}- A callable (closure, function name,
[Class::class, 'method']) is called as$formatter($value, $res). - A class name that is not callable is instantiated and called as
(new $formatter())->handle($value, $res). $resholds the component vars as passed (name,value,attrs); config defaults are not merged into it yet.
namespace App\Formatters;
class UpperFormatter{ public function handle($value, array $res) { return mb_strtoupper((string) $value); }}field_attrs
Section titled “field_attrs”lte3.view.field_attrs lists the attr keys that components print as HTML attributes on the input as key="value":
'field_attrs' => [ 'autocomplete', 'autofocus', 'accept', 'placeholder', 'required', 'maxlength', 'minlength', 'pattern', 'max', 'min', 'step', 'rows', 'title', 'alt', 'style', 'id', 'data-name', 'x-model',],- Keys from this list set to
falseornullare dropped, so'required' => $isRequiredis safe.0and''are still printed. trueis printed as"1"(required="1"), which browsers treat as present.- Add keys to print more attributes from the attrs array, e.g.
'inputmode'or'x-on:change'. patternenables live validation, see Pattern validation.data-nameis used by block repeaters to rename fields, see mb-blocks.
Components
Section titled “Components”| Name | Page | Blade |
|---|---|---|
text, number, email, url, search, password, secret | text | lte3::components.text |
textarea | textarea | lte3::components.textarea |
slug | slug | lte3::components.slug |
hidden | hidden | lte3::components.hidden |
colorpicker | colorpicker | lte3::components.colorpicker |
range | range | lte3::components.range |
checkbox | checkbox | lte3::components.checkbox |
checkboxes | checkboxes | lte3::components.checkboxes |
radiogroup | radiogroup | lte3::components.radiogroup |
select2 | select2 | lte3::components.select2 |
select2Tree | select2Tree | lte3::components.select2Tree |
treeview | treeview | lte3::components.treeview |
nestedset | nestedset | lte3::components.nestedset.tree |
xEditable | xEditable | lte3::components.xEditable |
links | links | lte3::components.links |
lists | lists | lte3::components.lists |
tableOptions | tableOptions | lte3::components.tableOptions |
datepicker, timepicker, datetimepicker, multidatespicker | datetime | lte3::components.datepicker, .timepicker, .datetimepicker, .multidatespicker |
file | file | lte3::components.file |
fileForm | fileForm | lte3::components.fileForm |
lfmFile, lfmImage | lfmFile | lte3::components.lfmFile |
mediaFile, mediaImage | mediaFile | lte3::components.mediaFile |
form (formOpen() / formClose()) | form | lte3::components.form |
link, btnSubmit, btnReset, btnModalClose | buttons | lte3::components.link, .btnSubmit, .btnReset, .btnModalClose |
Custom components
Section titled “Custom components”Add an entry to view.components and call it like any built-in field:
'view' => [ 'components' => [ // ... 'money' => [ 'blade' => 'admin.fields.money', 'vars' => ['name', 'value', 'attrs'], 'default' => ['currency' => 'UAH', 'default' => 0], ], ],],{{-- resources/views/admin/fields/money.blade.php --}}<div class="form-group {{ $attrs['class_wrap'] ?? '' }}"> <label>{!! $attrs['label'] ?? Str::studly($name) !!}</label> <div class="input-group"> <input type="number" step="0.01" name="{{ $name }}" value="{{ $value }}" class="form-control @error($name) is-invalid @enderror" @foreach(Arr::only($attrs, $field_attrs) as $key => $val) {{ $key }}="{{ $val }}" @endforeach > <div class="input-group-append"><span class="input-group-text">{{ $attrs['currency'] }}</span></div> </div> @error($name)<div class="invalid-feedback d-block">{{ $message }}</div>@enderror</div>{!! Lte3::money('price', null, ['label' => 'Price', 'required' => true]) !!}blade— any view name.vars— names of the positional arguments, passed to the view as variables. If bothnameandvalueare present, the value goes through Value resolution and the Formatter.default— attrs merged under the passed attrs;default.defaultis the fallback value.- The component also works with
Lte3::field(['type' => 'money', ...]).
Overriding a component view
Section titled “Overriding a component view”Publish the component views and edit the copies:
php artisan vendor:publish --tag=lte3-view-componentsThe files land in resources/views/vendor/lte3/components/ and take precedence over the package views with the same name. Alternatively, point the blade key of a component in your config to your own view.