Level 73
Can't you just mutate it to a date in your model and then cast it to a number when retrieving it?
https://laravel.com/docs/11.x/eloquent-mutators#defining-a-mutator
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I tried to used toggleColumn to block a user in the table lis, The problem is the blocked_at is timestamp.. I used hook beforeStateUpdated for now and was able to store data in the database but got some problem when I click the toggle.
I got this error
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1' for column 'blocked_at' at row 1 (Connection: mysql, SQL: update `users` set `blocked_at` = 1, `users`.`updated_at` = 2024-08-10 07:30:10 where `id` = 4)
This is my code
Tables\Columns\ToggleColumn::make('blocked_at')
->label('Block')
->onColor('success')
->offColor('danger')
->getStateUsing(fn ($record) => !is_null($record->blocked_at))
->beforeStateUpdated(function (bool $state, $record) {
$record->blocked_at = $state ? now() : null;
$record->blocked_by = $state ? auth()->id() : null;
$record->save();
}),
Please or to participate in this conversation.