ToggleColumn::make('status')
->label('Active')
->updateStateUsing(function ($record, $state) {
if (!$state) {
$schoolId = Filament::getTenant()->id;
$hasOtherActive = $record::where('id', '!=', $record->id)
->where('school_id', $schoolId)
->where('status', true)
->exists();
if (!$hasOtherActive) {
Notification::make()
->danger()
->title('Update Failed')
->body('There must be at least one active session.')
->send();
return $state = true;
}
} else {
return $record->update(['status' => $state]);
}
})
ToggleColumn::make('status')
->label('Active')
->updateStateUsing(function ($record, $state) {
if (!$state) {
$schoolId = Filament::getTenant()->id;
$hasOtherActive = $record::where('id', '!=', $record->id)
->where('school_id', $schoolId)
->where('status', true)
->exists();
if (!$hasOtherActive) {
Notification::make()
->danger()
->title('Update Failed')
->body('There must be at least one active session.')
->send();
return $state = true;
}
} else {
return $record->update(['status' => $state]);
}
})