Ce document n’est pas disponible en français (fr). La version en English (en) est affichée.
webkernel/platform-tables
07-toggle
Sur cette page
title: Toggle column
Introduction
The toggle column allows you to render a toggle button inside the table, which can be used to update that database record without needing to open a new page or a modal:
use Webkernel\Platform\Tables\Columns\ToggleColumn;
ToggleColumn::make('is_admin')
<AutoScreenshot name="tables/columns/toggle/simple" alt="Toggle column" />
Lifecycle hooks
Hooks may be used to execute code at various points within the toggle's lifecycle:
ToggleColumn::make()
->beforeStateUpdated(function ($record, $state) {
// Runs before the state is saved to the database.
})
->afterStateUpdated(function ($record, $state) {
// Runs after the state is saved to the database.
})
Security
Authorization
Toggle columns do not automatically check model policies. Without an authorization check, users can update the column for records accessible through the table query, even if the record's update() policy denies access to its edit page. Use disabled() with your authorization logic, for example disabled(fn ($record) => $record->user_id !== auth()->id()). Platform checks this condition on the server before saving.
Check permission for the specific attribute being changed, especially sensitive attributes such as administrator access. If the column updates a related model or pivot, authorize that operation too. Alternatively, use a resource edit page or a policy-backed EditAction to apply the resource's edit authorization.
