There are lots of Laravel packages pretending to wrap the widely popular Bootstrap CSS design system. Most of them are limited just to forms formatting (while Bootstrap provides so many different tools), and all of them have an elaborated syntax, so the code required to format your component is no so less verbose (nor more readable) then the actual resulting HTML.
Larastrap provides a conspicuous amount of (configurable) defaults and many out-of-the-box common behaviours. And, leveraging the Laravel's native Blade Components system, provides a few handy automatisms and the ability to define your own reusable Custom Elements.
To reduce to the bare minimum the code you have to actually write (and read, and maintain...) to obtain your desidered layout.
Get Rid of Boilerplate
We all love Bootstrap (booo, Tailwind, booo!), but we all know it also requires a lot of boilerplate code.
Repeated again and again across all the templates.
Here comes Larastrap, which already contains all the boilerplate parts and gives to you just the fun!
@php
$obj = App\Models\User::inRandomOrder()->first();
@endphp
<x-larastrap::form :obj="$obj" disabled>
<x-larastrap::text name="name" label="Name" />
<x-larastrap::text name="surname" label="Surname" value="Bar" />
<x-larastrap::email name="email" label="EMail" help="Must be a valid email address" />
</x-larastrap::form>
<form id="form-e4da3b7fbbce2345d7772b0674a318d5" class="" method="post" disabled name="form-e4da3b7fbbce2345d7772b0674a318d5">
<input type="hidden" name="_token" value="nWmG9gtn7MOxFq6xsDemxzKTOadAspDNoFQDOS47" autocomplete="off">
<div class="row mb-3" disabled>
<label for="input-7a8cc1c5c15fc319ff79d62dcb5131d5" class="col-4 col-form-label">Name</label>
<div class="col-8">
<input id="input-7a8cc1c5c15fc319ff79d62dcb5131d5" type="text" class="form-control" name="name" value="Shany Bosco" disabled>
</div>
</div>
<div class="row mb-3" disabled>
<label for="input-1b9ab67c1738341913d2a646badb8165" class="col-4 col-form-label">Surname</label>
<div class="col-8">
<input id="input-1b9ab67c1738341913d2a646badb8165" type="text" class="form-control" name="surname" value="Bar" disabled>
</div>
</div>
<div class="row mb-3" disabled>
<label for="input-af8df4d5bfa8c1e962bfaff0cc6b9328" class="col-4 col-form-label">EMail</label>
<div class="col-8">
<input id="input-af8df4d5bfa8c1e962bfaff0cc6b9328" type="email" class="form-control" name="email" value="kasandra.zboncak@example.com" disabled aria-describedby="help-input-af8df4d5bfa8c1e962bfaff0cc6b9328">
<div class="form-text" id="help-input-af8df4d5bfa8c1e962bfaff0cc6b9328">
Must be a valid email address
</div>
</div>
</div>
<div class="col-12 text-end">
<button id="button-164a4c62adbafbf0b1a6145635bd6be6" class="btn btn-primary" disabled type="submit">Save</button>
</div>
</form>
Global Configuration
Each component has many parameters that can be set in the global configuration file. Change once any value to an immediate impact on layout, behavior, colors and strings across your application!
[
// Default settings...
]
[
'form' => [
'formview' => 'vertical',
'buttons_align' => 'start',
]
]
[
'form' => [
'formview' => 'vertical',
'buttons_align' => 'start',
'buttons' => [
[
'color' => 'danger',
'label' => 'Save',
'attributes' => ['type' => 'submit']
]
]
],
'field' => [
'label_class' => 'text-danger',
]
]
[
'form' => [
'formview' => 'vertical',
'buttons_align' => 'start',
'buttons' => [
[
'color' => 'danger',
'label' => 'Submit',
'classes' => ['mt-5', 'btn-lg'],
'attributes' => ['type' => 'submit']
]
]
],
'field' => [
'label_class' => 'text-danger display-5',
],
'text' => [
'classes' => ['form-control-lg'],
],
'email' => [
'classes' => ['form-control-lg'],
]
]
Implement Once
Did you noticed the "copy to clipboard" element on top of this page? It is a Custom Element!
With a few lines of code in the global configuration you can define custom, reusable components to be used in your templates with just a single Blade tag, and to be maintained in a single place with no effort.
[
'customs' => [
'command' => [
'extends' => 'text',
'params' => [
'classes' => ['command'],
'attributes' => ['readonly' => 'readonly'],
'textappend' => '<i class="bi bi-clipboard"></i>',
'squeeze' => true
]
]
]
]
<x-larastrap::command value="Copy this to the clipboard" />
<div class="input-group">
<input id="input-c994ac843d0af9a1f2163dfaaba6ec3f" type="text" class="command form-control" name="ziDoNNyWSM" value="Copy this to the clipboard" readonly="readonly">
</div>