-
Notifications
You must be signed in to change notification settings - Fork 4
FieldBag
Emeka Mbah edited this page May 21, 2023
·
2 revisions
The FieldBag alert provides some fluent methods for displaying multiple messages for form fields.
The FieldBag alert has lots of helpful methods that makes it easy to use
This feature enables you to display validation errors, it accepts validator instance
Example:
In the application
$validator = validator(
[
'username' => '',
'password' => 'pass'
],
[
'username' => 'required',
'password' => 'required|min:6'
]
);
Alert::fieldBag($validator)
->tag('login')
->error()
->flash();
In the blade
<div class="col-lg-12 mb4">
<div class="card mb-4">
<div class="card-body">
<form class="row g-3 needs-validation" novalidate>
<div class="col-md-6 position-relative">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" value="" required>
<x-alert-field name="username" tag="login" />
</div>
<div class="col-md-6 position-relative">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" value="" required>
<x-alert-field name="password" tag="login" />
</div>
<div class="col-12">
<button class="btn btn-primary" type="submit">Update</button>
</div>
</form>
</div>
</div>
</div>
Result
The field level is the color of the field message. The available levels are:
Alert::fieldBag(...)->primary();
Alert::fieldBag(...)->secondary();
Alert::fieldBag(...)->success();
Alert::fieldBag(...)->info();
Alert::fieldBag(...)->error();
Alert::fieldBag(...)->warning();
Alert::fieldBag(...)->light();
Alert::fieldBag(...)->dark();