Tables\Columns\SelectColumn::make('status')
->options(
[
'publish' => 'Publish',//I would love to add an icon here and change the color
'unPublish' => 'UnPublish',
'markAsFeatured' => 'Feature',
'unmarkAsFeatured' => 'Unfeature'
]
)->updateStateUsing(function ($state, $record) {
switch ($state) {
case 'publish':
$record->publish();
break;
case 'unPublish':
$record->unpublish();
break;
case 'markAsFeatured':
$record->markAsFeatured();
break;
case 'unmarkAsFeatured':
$record->unmarkAsFeatured();
break;
}
}
)->disableOptionWhen(
function (string $value,$record): bool {
return match ($value) {
'publish' => $record->isDraft(),
'unPublish' => $record->isPublished(),
'markAsFeatured' => !$record->isFeatured(),
'unmarkAsFeatured' => $record->isFeatured(),
default => false,
};
}
)->placeholder(function ($state, $record) {
if ($record->trashed()) {
return 'heroicon-s-trash';
}
if ($record->isFeatured()) {
return 'heroicon-s-star';
}
if ($record->isPublished()) {
return 'heroicon-s-globe-europe-africa';
}
if ($record->isDraft()) {
return 'heroicon-s-pencil';
}
return 'heroicon-s-question-mark-circle';
})
->disabled(fn($state, $record) => $record->trashed()),