digitallyhappy/toggle-field-for-backpack
A toggle switch field for Backpack for Laravel admin panels, letting you edit boolean columns with a clean on/off switch instead of a checkbox. Drop it into your field definitions to make true/false settings faster and clearer to manage.
composer require digitallyhappy/toggle-field-for-backpack. Use 2.0.1 or later if you're on Backpack v5 — v5 support landed in this release (PR #8). On Backpack v4, either version works, but pin deliberately if you have a lockfile in CI.resources/views/vendor/backpack/crud/fields/toggle.blade.php). If you previously copied the blade file to the wrong path during a v4 → v5 upgrade, that's the fix.is_active. In your CrudController:$this->crud->addField([
'name' => 'is_active',
'label' => 'Active',
'type' => 'toggle',
]);
$this->crud->addColumn(['name' => 'is_active', 'type' => 'boolean']);
$table->boolean('is_active')->default(false);setupCreateOperation() and setupUpdateOperation() so the two forms never drift:protected function addStatusFields(): void
{
$this->crud->addField([
'name' => 'is_active',
'type' => 'toggle',
'label' => 'Active',
'default' => false,
]);
}
select in a "Publishing" fieldset rather than giving it its own tab; a lone toggle in a tab looks broken to editors.'default' => false explicitly, otherwise the first render shows an ambiguous state.'is_active' => 'boolean' to $casts. The field posts 0/1; without a cast you'll be comparing "0" strings in scopes and policies and getting surprises.'is_active' => ['boolean'] (not required) — a toggle that's off still submits a value, but required semantics get confusing when you later add nullable states.scopeActive() on the model and a dropdown/select filter rather than trying to reuse the toggle as a filter.composer update doesn't wipe your styling. This is the same view path the README now documents.<input type="checkbox"> submits nothing when off. Backpack toggle fields normally pair the checkbox with a hidden 0 input; if you override the blade view, keep that hidden input or every "off" save will be interpreted as "leave unchanged" or fail validation.View [toggle] not found. Almost always a v4/v5 path mismatch or a missing publish step. Confirm the blade file sits under resources/views/vendor/backpack/crud/fields/ (v5 location). This is exactly the confusion the README fix in 2.0.1 addresses.null/0/1) and enum-backed flags don't map cleanly onto a two-position toggle; use a select with an explicit "unset" option instead.type => 'boolean' columns render nicely in the UI but often export as 1/0. If you need "Yes/No" in CSV exports, format in an exporter rather than fighting the column.dd($request->all()) in the store method — is is_active present at all?), the model's $fillable, then the cast. The field itself is rarely the culprit.How can I help you explore Laravel packages today?