v0.0.1-alpha 2019-07-05 09:34 UTC

This package is auto-updated.

Last update: 2023-09-19 06:33:27 UTC


Software License Build Status StyleCI Scrutinizer Code Quality Build Status

This package allows you to quickly implement toggle switch fields logic into your Laravel Controllers. It comes with different field type support (boolean and timestamp) out of the box and allows you to add custom logic yourself. This package does not provide any implementation of Toggle Switch buttons on the front-end, but just the logic needed to make any Toggle Switch work.


In order to install this package, just run

composer require soarecostin/laravel-toggle-switch-fields



You can publish the configuration file, that contains all the available checks using:

php artisan vendor:publish --provider=SoareCostin\LaravelToggleSwitchFields\ToggleSwitchFieldsServiceProvider

This will publish a toggle_switch_fields.php file in your config folder.

Available Configuration Options

The following options are available:

  • Default field name - will be used as the default field name that will be toggled, for all controllers. The default value is published. You can overwrite this setting per each controller, as explained below, in the Controllers section
default_field => 'published'


For each Laravel Controller where you want to implement the toggle switch logic for some fields, add the use Switchable trait from this package:

use App\Http\Controllers\Controller;
use SoareCostin\LaravelToggleSwitchFields\Traits\Switchable;

class YourCustomController extends Controller
    use Switchable;
    // ...

This trait will add two functions to your controller: switchOn and switchOff


Add the following to your routes.php file:

use SoareCostin\LaravelToggleSwitchFields\Facades\ToggleSwitchFields;

ToggleSwitchFields::routes('/your-custom-url/{your-custom-route-param}', 'YourCustomController', 'your.custom.route.prefix');


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.


Please see CHANGELOG for more information.


This library is licensed under the MIT license. Please see License file for more information.