A customizable and configurable toggle switch button generator for Laravel that enables you to simply display it on your projects pages.
- Install the package with composer :
composer require okipa/laravel-toggle-switch-button- Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider and the Facade alias.
If you don't use auto-discovery or if you use a Laravel 5.4- version, add the package service provider in the
register()method from yourapp/Providers/AppServiceProvider.php:
// laravel toggle switch button
// https://github.com/Okipa/laravel-toggle-switch-button
$this->app->register(Okipa\LaravelToggleSwitchButton\ToggleSwitchButtonServiceProvider::class);- Then, add the facade of this package to the
$aliasesarray of the from yourconfig/app.phpfile :
'ToggleSwitchButton' => Okipa\LaravelToggleSwitchButton\Facades\ToggleSwitchButton::class,- Load the package
SASSorCSSfile from the[path/to/composer/vendor]/okipa/laravel-toggle-switch-button/stylesdirectory to your project.
Simply call the toggle switch button rendering in your form as precised in the following example :
{!! ToggleSwitchButton::render(
'active',
old('active'),
'<i class="fa fa-power-off" aria-hidden="true"></i>',
'Status'
) !!}Parameters :
- (required) string $inputName : set the input name. Also used by default for the input id.
- (optional) bool $inputChecked : determine whether your toggle switch button is checked or not.
- (optional) string $labelIcon : set the icon that will appear before the toggle switch button.
- (optional) string $labelString : set the label that will appear before the toggle switch button.
- (optional) string $inputId : set the input id. If not filled, the input name will be used.
If you use CSS, just override the package styles.
If you use SASS, you can override the following variables before the package SASS file import. Check the following example for a bootstrap use :
// bootstrap 4 example
$toggle_switch_button_label_background_color: $input-group-addon-bg;
$toggle_switch_button_label_border_color: $input-group-addon-border-color;
$toggle_switch_button_label_font_size: $font-size-base;
$toggle_switch_button_unchecked_background_color: $input-group-addon-border-color;
$toggle_switch_button_checked_background_color: $primary;
$toggle_switch_button_border_radius: $btn-border-radius;
@import '[path/to/composer/vendor]/okipa/laravel-toggle-switch-button/styles/styles';Publish the package blade templates file in your project :
php artisan vendor:publish --tag=toggle-switch-button::viewsThen, change the content from your resources/views/vendor/toggle-switch-button/switch-button.blade.php file.

