class ShopResource extends Resource
{
protected static ?string $model = Shop::class;
protected static string|\UnitEnum|null $navigationGroup = 'Users';
public static function getRecordRouteKeyName(): ?string
{
return 'name';
}
public static function table(Table $table): Table
{
return $table
->persistFiltersInSession()
->columns([
TextColumn::make('name')
->toggleable()
->searchable()
->sortable(),
IconColumn::make('vacation')
->label(new HtmlString('Active /
Not on Vacation'))
->getStateUsing(fn (Shop $record) => ! $record->vacation)
->alignCenter()
->toggleable()
->boolean(),
IconColumn::make('suspended')
->label(new HtmlString('Allowed /
Not Suspended'))
->getStateUsing(fn (Shop $record) => ! $record->suspended)
->toggleable()
->alignCenter()
->boolean(),
TextColumn::make('created_at')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('deleted_at')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
TrashedFilter::make(),
TernaryFilter::make('suspended'),
TernaryFilter::make('vacation'),
])
->recordActions([
ViewAction::make(),
EditAction::make(),
ActionGroup::make([
Action::make('Suspend')
->button()
->visible(fn (Shop $record): bool => ! $record->suspended)
->color('danger')
->requiresConfirmation()
->action(fn (Shop $record) => SuspendShopAction::run($record))
->after(
fn (Shop $record) => Notification::make()
->danger()
->body("Shop {$record->name} has been suspended")
->send()
),
Action::make('Remove Suspension')
->button()
->visible(fn (Shop $record): bool => $record->suspended)
->color('success')
->action(fn (Shop $record) => UnsuspendShopAction::run($record))
->after(
fn () => Notification::make()
->success()
->body('The shop has been restored')
->send()
),
Action::make('Send on Vacation')
->button()
->visible(fn (Shop $record): bool => ! $record->vacation)
->color('danger')
->requiresConfirmation()
->action(fn (Shop $record) => ShopGoesOnVacationAction::run($record))
->after(
fn (Shop $record) => Notification::make()
->danger()
->body("Shop {$record->name} has been sent on vacation")
->send()
),
Action::make('Return from Vacation')
->button()
->visible(fn (Shop $record): bool => $record->vacation)
->color('success')
->action(function (Shop $record) {
ray('Returning from vacation inline');
ShopReturnsFromVacationAction::run($record);
})
->after(
fn (Shop $record) => Notification::make()
->success()
->body("Shop {$record->name} has returned from vacation")
->send()
),
]),
])
->headerActions([
UserResource::makeUserAction(
'Create Vendor & Shop',
fn ($password, $data) => User::factory()->vendorUser($password)->create($data)
),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
ForceDeleteBulkAction::make(),
RestoreBulkAction::make(),
Action::make('Suspend')
->color('danger')
->icon('heroicon-o-exclamation-circle')
->requiresConfirmation()
->accessSelectedRecords()
->action(fn (Collection $selectedRecords) => $selectedRecords->each(
fn (Shop $record) => SuspendShopAction::run($record)
))
->after(
fn (Collection $collection) => Notification::make()
->danger()
->body("{$collection->count()} Shop(s) have been suspended")
->send()
),
Action::make('Remove Suspension')
->color('success')
->icon('heroicon-o-arrow-uturn-right')
->accessSelectedRecords()
->action(fn (Collection $selectedRecords) => $selectedRecords->each(
fn (Shop $record) => UnsuspendShopAction::run($record)
))
->after(
fn (Collection $collection) => Notification::make()
->success()
->body("{$collection->count()} Shop(s) have been restored")
->send()
),
Action::make('Send on Vacation')
->color('danger')
->icon('heroicon-o-x-circle')
->requiresConfirmation()
->accessSelectedRecords()
->action(fn (Collection $selectedRecords) => $selectedRecords->each(
fn (Shop $record) => ShopGoesOnVacationAction::run($record)
))
->after(
fn (Collection $collection) => Notification::make()
->danger()
->body("{$collection->count()} Shop(s) have been sent of vacation")
->send()
),
Action::make('Return from Vacation')
->color('success')
->icon('heroicon-o-arrow-uturn-right')
->accessSelectedRecords()
->action(fn (Collection $selectedRecords) => $selectedRecords->each(
function (Shop $record) {
ray('Returning from vacation', ['shop' => $record]);
ShopReturnsFromVacationAction::run($record);
})
)
->after(
fn (Collection $collection) => Notification::make()
->success()
->body("{$collection->count()} Shop(s) have been returned from vacation")
->send()
),
]),
]);
}