Skip to content

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.

{!! Lte3::text('title', null, ['label' => 'Title', 'required' => true]) !!}
  • Lte3 is an alias of Fomvasss\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 throws Exception: Lte3 method or component '<name>' not found!.

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 component default array from the config merged with the attrs you passed (yours win).
  • $field_attrs — the lte3.view.field_attrs list.
  • $model — the model of the current Lte3::formOpen(['model' => ...]), unless the component has its own model var that you passed.

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'],
]) !!}
  • type is the component name from the config, text by default.
  • The two arrays are merged ($params2 wins).
  • 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, not null.
  • The whole merged array is passed as attrs, so label, help, class, etc. go at the top level next to name.

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.

AttrTypeDefaultDescription
labelstringstudly nameLabel 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.
helpstring-Help text under the field (HTML, printed unescaped).
classstring-Extra classes of the input element.
class_wrapstring-Extra classes of the wrapping .form-group, e.g. grid classes.
hidden_wrapboolfalseRenders the wrapper with the hidden attribute.
disabledboolfalseAny truthy value adds disabled.
readonlyboolfalseAny truthy value adds readonly (in components that support it).
attrsarray[]Arbitrary HTML attributes printed on the input as key="value" (text, textarea, hidden, checkbox, checkboxes, radiogroup, select2, select2Tree, xEditable).
dataarray[]data-* attributes: ['compare-value' => 42] gives data-compare-value="42" (text, textarea, select2, radiogroup, treeview).
defaultmixed-Value used when nothing else provides one, see Value resolution.
formattercallable or class-Transforms the resolved value before rendering, see Formatter.
field_attrs keysmixed-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.

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:

  1. old($name) — the input flashed after a failed validation.
  2. request($name) — the current request query/body.
  3. The $value argument, if not null.
  4. The form model, if Lte3::formOpen(['model' => $model]) is open: $model->getFormValue($key) when the model has such a method, otherwise data_get($model, $key).
  5. The default attr (from your attrs, or from the component default.default in the config).

Notes:

  • The name is converted to a dot key for lookups: meta[title] becomes meta.title, tags[] becomes tags, and . becomes _ (as PHP does with request keys).
  • Steps 1 and 2 are skipped for the field named _method.
  • If the ConvertEmptyStringsToNull middleware is active, there are validation errors and both old() and $value are null, the result is null (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, so default only applies to forms without a model.
  • Components with other vars (selected, path, items) resolve their values in their own views; see their pages.

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 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).
  • $res holds 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);
}
}

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 false or null are dropped, so 'required' => $isRequired is safe. 0 and '' are still printed.
  • true is 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'.
  • pattern enables live validation, see Pattern validation.
  • data-name is used by block repeaters to rename fields, see mb-blocks.
NamePageBlade
text, number, email, url, search, password, secrettextlte3::components.text
textareatextarealte3::components.textarea
slugsluglte3::components.slug
hiddenhiddenlte3::components.hidden
colorpickercolorpickerlte3::components.colorpicker
rangerangelte3::components.range
checkboxcheckboxlte3::components.checkbox
checkboxescheckboxeslte3::components.checkboxes
radiogroupradiogrouplte3::components.radiogroup
select2select2lte3::components.select2
select2Treeselect2Treelte3::components.select2Tree
treeviewtreeviewlte3::components.treeview
nestedsetnestedsetlte3::components.nestedset.tree
xEditablexEditablelte3::components.xEditable
linkslinkslte3::components.links
listslistslte3::components.lists
tableOptionstableOptionslte3::components.tableOptions
datepicker, timepicker, datetimepicker, multidatespickerdatetimelte3::components.datepicker, .timepicker, .datetimepicker, .multidatespicker
filefilelte3::components.file
fileFormfileFormlte3::components.fileForm
lfmFile, lfmImagelfmFilelte3::components.lfmFile
mediaFile, mediaImagemediaFilelte3::components.mediaFile
form (formOpen() / formClose())formlte3::components.form
link, btnSubmit, btnReset, btnModalClosebuttonslte3::components.link, .btnSubmit, .btnReset, .btnModalClose

Add an entry to view.components and call it like any built-in field:

config/lte3.php
'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 both name and value are present, the value goes through Value resolution and the Formatter.
  • default — attrs merged under the passed attrs; default.default is the fallback value.
  • The component also works with Lte3::field(['type' => 'money', ...]).

Publish the component views and edit the copies:

Terminal window
php artisan vendor:publish --tag=lte3-view-components

The 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.