This package contains a set of useful Bootstrap Laravel Blade components. It promotes DRY principles and allows you to keep your HTML nice and clean. Components include alerts, badges, buttons, form inputs (with automatic error feedback), dropdowns, navs, pagination (responsive), and more. The components come with Laravel Livewire integration built in, so you can use them with or without Livewire.
- Bootstrap 5 must be installed via webpack first
- Font Awesome must be installed to use icons
Require the package via composer:
composer require bastinald/laravel-bootstrap-components
A Bootstrap alert:
<x-bs::alert
:label="__('It was successful!')"
color="info"
dismissible
/>
-
icon
: Font Awesome icon to show before label e.g.cog
,envelope
-
label
: label to display, can also be placed in theslot
-
color
: Bootstrap color e.g.primary
,danger
,success
-
dismissible
: set the alert to be dismissible
A Bootstrap badge:
<x-bs::badge
:label="__('Pending')"
color="warning"
/>
-
icon
: Font Awesome icon to show before label e.g.cog
,envelope
-
label
: label to display, can also be placed in theslot
-
color
: Bootstrap color e.g.primary
,danger
,success
A Bootstrap button:
<x-bs::button
:label="__('Login')"
color="primary"
size="lg"
route="login"
/>
-
icon
: Font Awesome icon to show before label e.g.cog
,envelope
-
label
: label to display, can also be placed in theslot
-
color
: Bootstrap color e.g.primary
,danger
,success
-
size
: Bootstrap button size e.g.sm
,lg
-
type
: button type e.g.button
,submit
-
route
: sets thehref
to a route -
url
: sets thehref
to a url -
href
: sets thehref
-
dismiss
: adata-bs-dismiss
value e.g.alert
,modal
-
toggle
: adata-bs-toggle
value e.g.collapse
,dropdown
-
click
: Livewire action on click -
confirm
: prompts the user for confirmation on click
A Bootstrap checkbox input:
<x-bs::check
:label="__('Agree')"
:checkLabel="__('I agree to the TOS')"
:help="__('Please accept the TOS.')"
switch
model="agree"
/>
-
label
: label to display above the input -
checkLabel
: label to display beside the input -
help
: helper label to display under the input -
switch
: style the input as a switch -
model
: Livewire model property key -
lazy
: bind Livewire data on change
A Bootstrap close button:
<x-bs::close
dismiss="modal"
/>
-
color
: Bootstrap close color e.g.white
-
dismiss
: adata-bs-dismiss
value e.g.alert
,modal
A Bootstrap color picker input:
<x-bs::color
:label="__('Favorite Color')"
:prepend="__('I like')"
:append="_('the most.')"
:help="__('Please pick a color.')"
model="favorite_color"
/>
-
label
: label to display above the input -
icon
: Font Awesome icon to show before input e.g.cog
,envelope
-
prepend
: addon to display before input, can be used via named slot -
append
: addon to display after input, can be used via named slot -
size
: Bootstrap input size e.g.sm
,lg
-
help
: helper label to display under the input -
model
: Livewire model property key -
lazy
: bind Livewire data on change
A Bootstrap datalist input:
<x-bs::datalist
:label="__('City Name')"
:options="['Toronto', 'Montreal', 'Las Vegas']"
:prepend="__('I live in')"
:append="_('right now.')"
:help="__('Please enter your city.')"
model="city_name"
/>
-
label
: label to display above the input -
options
: array of input options e.g.['Red', 'Blue']
-
icon
: Font Awesome icon to show before input e.g.cog
,envelope
-
prepend
: addon to display before input, can be used via named slot -
append
: addon to display after input, can be used via named slot -
size
: Bootstrap input size e.g.sm
,lg
-
help
: helper label to display under the input -
model
: Livewire model property key -
debounce
: time in ms to bind Livewire data on keyup e.g.500
-
lazy
: bind Livewire data on change
A description list:
<x-bs::desc
:term="__('ID')"
:details="$user->id"
/>
-
tern
: the description list term -
details
: the description list details, can also be placed in theslot
-
date
: date to use instead of details (for use with Laravel Timezone)
A Bootstrap dropdown:
<x-bs::dropdown
:label="__('Filter')"
color="danger"
>
<x-bs::dropdown-item
:label="__('By Name')"
click="$set('filter', 'name')"
/>
<x-bs::dropdown-item
:label="__('By Age')"
click="$set('filter', 'age')"
/>
</x-bs::dropdown>
-
icon
: Font Awesome icon to show before label e.g.cog
,envelope
-
label
: dropdown label to display, can be used via named slot -
items
: dropdown items, can also be placed in theslot
-
color
: Bootstrap color e.g.primary
,danger
,success
-
size
: Bootstrap button size e.g.sm
,lg
A Bootstrap dropdown menu item:
<x-bs::dropdown-item
:label="__('Login')"
route="login"
/>
-
icon
: Font Awesome icon to show before label e.g.cog
,envelope
-
label
: label to display, can also be placed in theslot
-
route
: sets thehref
to a route -
url
: sets thehref
to a url -
href
: sets thehref
A Bootstrap form:
<x-bs::form submit="login">
<x-bs::input :label="__('Email')" type="email" model="email"/>
<x-bs::input :label="__('Password')" type="password" model="password"/>
<x-bs::button :label="__('Login')" type="submit"/>
</x-bs::form>
-
submit
: Livewire action on submit
A Font Awesome icon:
<x-bs::icon
name="cog"
/>
-
name
: Font Awesome icon name e.g.cog
,rocket
-
style
: Font Awesome icon style e.g.solid
,regular
,brands
-
size
: Font Awesome icon size e.g.sm
,lg
,3x
,5x
-
color
: Bootstrap color e.g.primary
,danger
,success
-
spin
: sets the icon to use a spin animation -
pulse
: sets the icon to use a pulse animation
An image:
<x-bs::image
asset="images/logo.png"
height="24"
rounded
/>
-
asset
: sets thesrc
to an asset -
src
: sets thesrc
-
fluid
: sets the image to be fluid width -
thumbnail
: sets the image to use thumbnail styling -
rounded
: sets the image to have rounded corners
A Bootstrap text input:
<x-bs::input
:label="__('Email Address')"
type="email"
:help="__('Please enter your email.')"
model="email_address"
>
<x-slot name="prepend">
<i class="fa fa-envelope"></i>
</x-slot>
</x-bs::input>
-
label
: label to display above the input -
type
: input type e.g.text
,email
-
icon
: Font Awesome icon to show before input e.g.cog
,envelope
-
prepend
: addon to display before input, can be used via named slot -
append
: addon to display after input, can be used via named slot -
size
: Bootstrap input size e.g.sm
,lg
-
help
: helper label to display under the input -
model
: Livewire model property key -
debounce
: time in ms to bind Livewire data on keyup e.g.500
-
lazy
: bind Livewire data on change
A hyperlink:
<x-bs::link
:label="__('Users')"
route="users"
/>
-
icon
: Font Awesome icon to show before label e.g.cog
,envelope
-
label
: label to display, can also be placed in theslot
-
route
: sets thehref
to a route -
url
: sets thehref
to a url -
href
: sets thehref
A Bootstrap nav dropdown:
<x-bs::nav-dropdown
:label="Auth::user()->name"
>
<x-bs::dropdown-item
:label="__('Update Profile')"
click="$emit('showModal', 'profile.update')"
/>
<x-bs::dropdown-item
:label="__('Logout')"
click="logout"
/>
</x-bs::nav-dropdown>
-
icon
: Font Awesome icon to show before label e.g.cog
,envelope
-
label
: dropdown label to display, can be used via named slot -
items
: dropdown items, can also be placed in theslot
A Bootstrap nav link:
<x-bs::nav-link
:label="__('Users')"
route="users"
/>
-
icon
: Font Awesome icon to show before label e.g.cog
,envelope
-
label
: label to display, can also be placed in theslot
-
route
: sets thehref
to a route -
url
: sets thehref
to a url -
href
: sets thehref
Responsive Bootstrap pagination links:
<x-bs::pagination
:links="App\Models\User::paginate()"
justify="center"
/>
-
links
: paginated Laravel models -
justify
: Bootstrap justification e.g.start
,end
A Bootstrap progress bar:
<x-bs::progress
:label="__('25% Complete')"
percent="25"
color="success"
height="10"
animated
striped
/>
-
label
: label to display inside the progress bar -
percent
: percentage of the progress bar -
color
: Bootstrap color e.g.primary
,danger
,success
-
height
: height of the progress bar in pixels -
animated
: animate the progress bar -
striped
: use striped styling for the progress bar
A Bootstrap radio input:
<x-bs::radio
:label="__('Gender')"
:options="['Male', 'Female']"
:help="__('Please select your gender.')"
switch
model="gender"
/>
-
label
: label to display above the input -
options
: array of input options e.g.['Red', 'Blue']
-
help
: helper label to display under the input -
switch
: sets the input to use a switch style -
model
: Livewire model property key -
lazy
: bind Livewire data on change
A Bootstrap select input:
<x-bs::select
:label="__('Your Country')"
:placeholder="__('Select Country')"
:options="['Australia', 'Canada', 'USA']"
:prepend="__('I live in')"
:append="_('right now.')"
:help="__('Please select your country.')"
model="your_country"
/>
-
label
: label to display above the input -
placeholder
: placeholder to use for the empty first option -
options
: array of input options e.g.['Red', 'Blue']
-
icon
: Font Awesome icon to show before input e.g.cog
,envelope
-
prepend
: addon to display before input, can be used via named slot -
append
: addon to display after input, can be used via named slot -
size
: Bootstrap input size e.g.sm
,lg
-
help
: helper label to display under the input -
model
: Livewire model property key -
lazy
: bind Livewire data on change
A Bootstrap textarea input:
<x-bs::textarea
:label="__('Biography')"
rows="5"
:help="__('Please tell us about yourself.')"
model="biography"
/>
-
label
: label to display above the input -
icon
: Font Awesome icon to show before input e.g.cog
,envelope
-
prepend
: addon to display before input, can be used via named slot -
append
: addon to display after input, can be used via named slot -
size
: Bootstrap input size e.g.sm
,lg
-
help
: helper label to display under the input -
model
: Livewire model property key -
debounce
: time in ms to bind Livewire data on keyup e.g.500
-
lazy
: bind Livewire data on change
This trait makes form data model manipulation a breeze. No more having to create a Livewire component property for every single form input. All form data will be placed inside the $model
property array.
Get the model data as a collection:
$collection = $this->model();
Set a single value:
$this->setModel('name', 'Kevin');
Set values using Eloquent model data:
$this->setModel(User::first());
Set values using an array:
$this->setModel([
'name' => 'Kevin',
'email' => 'kevin@example.com',
]);
Add an empty array item:
$this->addModelItem('locations');
Remove an array item by its key:
$this->removeModelItem('locations', 3);
Order an array item by its key & direction:
$this->orderModelItem('locations', 3, 'up');
The direction should be up
or down
.
Package components work with this trait via the model
attribute:
<x-bs::input :label="__('Name')" model="name"/>
<x-bs::input :label="__('Email')" type="email" model="email"/>
Use the validateModel
method to validate model data:
$this->validateModel([
'name' => ['required'],
'email' => ['required', 'email'],
]);
This method works just like the Livewire validate
method, so you can specify your rules in a separate rules
method if you prefer.
Use your own component views by publishing the package views:
php artisan vendor:publish --tag=laravel-bootstrap-components:views
Now edit the files inside resources/views/vendor/bs
. The package will use these files to render the components.
Use your own font icons by publishing the package config:
php artisan vendor:publish --tag=laravel-bootstrap-components:config
Now edit the icon_class_prefix
value inside config/laravel-bootstrap-components.php
. The package will use this class to render the icons.