Downloads
Stars
Version
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.
The following options are available:
published
. You can overwrite this setting per each controller, as explained below, in the Controllers sectiondefault_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.