Tables\Columns\ToggleColumn::make('pinned')
->tooltip(fn(News $record): string => $record->pinned ? 'Unpin' : 'Pin')
->action(function (News $record) {
// This does not work...
if(News::wherePinned(true)->count >= 3) {
Notification::make('Error')
->body('You can pin only 3 news.')
->danger()
->send();
} else {
$record->update(['pinned' => true]);
}
})
->disabled(fn(News $record) => $record->pinned == false && News::wherePinned(true)->count() >= 3),
Tables\Columns\ToggleColumn::make('pinned')
->tooltip(fn(News $record): string => $record->pinned ? 'Unpin' : 'Pin')
->action(function (News $record) {
// This does not work...
if(News::wherePinned(true)->count >= 3) {
Notification::make('Error')
->body('You can pin only 3 news.')
->danger()
->send();
} else {
$record->update(['pinned' => true]);
}
})
->disabled(fn(News $record) => $record->pinned == false && News::wherePinned(true)->count() >= 3),