# Button
This class allows you to generate a button.
Example:
Button::add()
->route('boilerplate.users.edit', $user->id)
->icon('pencil-alt')
->color('primary')
->make();
| method | description |
|---|---|
| add | Creates a new button |
| icon | Adds a FontAwesome icon to the button |
| color | Sets the button color |
| class | Sets additional class |
| route | Sets the button link href by using a route |
| link | Sets the button link href |
| tooltip | Sets a tooltip for the button |
| attributes | Sets HTML attributes to the button |
| make | Renders the button |
# add
Creates a new button.
Button::add()
You can specify a label:
Button::add('Edit')
# icon
Adds a FontAwesome icon to the button:
Available icons: https://fontawesome.com/v5.15/icons (opens new window)
You only have to specify the name of the icon:
->icon('edit')
For other styles than fas, specify last letter of the class:
->icon('calendar', 'r')
# color
Sets the button color.
Available colors: https://getbootstrap.com/docs/4.0/utilities/colors/ (opens new window)
Only bootstrap4 colors are supported.
->color('primary')
# class
Sets additional class.
->class('mr-1 text-sm')
# route
Sets the button link href by using a route.
->route('boilerplate.users.edit', $user->id)
# link
Sets the button link href.
->link(route('boilerplate.users.edit', $user->id))
# tooltip
Sets a tooltip for the button using the HTML title attribute.
->tooltip('Edit this user')
The tooltip is only rendered when a non-empty string is provided, avoiding unnecessary HTML attributes.
Example with tooltip:
Button::add('Edit')
->route('boilerplate.users.edit', $user->id)
->icon('pencil-alt')
->color('primary')
->tooltip('Edit this user')
->make();
# attributes
Sets HTML attributes.
->attributes(['data-action' => 'delete'])
# make
Renders the button.
->make()
# Button aliases
# Predefined buttons
Button::show('route.to.resource.show', $resource);
Button::edit('route.to.resource.edit', $resource);
Button::delete('route.to.resource.destroy', $resource);
Button::deletewill show a modal to confirm the deletion. You can set another confirmation message by using theDatatable::locale()method.
# Custom button helper
The custom() method provides a convenient way to create custom buttons with all parameters in a single call:
Button::custom(
'route.name', // Route name (required)
$args, // Route arguments (optional, default: [])
'icon-name', // FontAwesome icon (optional, default: '')
'Tooltip text', // Tooltip text (optional, default: '')
'primary', // Button color (optional, default: 'default')
['data-action' => 'x'] // HTML attributes (optional, default: [])
);
Example:
Button::custom(
'users.export',
['id' => $user->id],
'download',
'Export user data',
'success',
['data-confirm' => 'Export this user?']
);
Note: The icon parameter comes before the tooltip for better ergonomics. If no icon is provided, no empty HTML markup is generated.