components([ Select::make('location_id') ->label('Lokus Utama') ->options(Location::query()->pluck('name', 'id')) ->searchable() ->native(false) ->required() ->rules(['exists:locations,id']) ->autofocus(), TextInput::make('name') ->label('Nama Sublokus') ->placeholder('Kecamatan Purwakarta') ->autocomplete(false) ->required() ->maxLength(50), ]) ->columns(1); } public static function table(Table $table): Table { return $table ->columns([ ...RowIndexColumn::make(), TextColumn::make('name') ->label('Nama') ->searchable() ->sortable(), ToggleColumn::make('is_active') ->label('Aktif?') ->sortable() ->getStateUsing(fn (SubLocation $record): bool => $record->is_active === IsActive::ACTIVE) ->updateStateUsing(function (SubLocation $record, bool $state): void { $record->is_active = $state ? IsActive::ACTIVE : IsActive::INACTIVE; $record->save(); CheerfulNotification::statusUpdated()->send(); }), ...TimestampColumns::make(), ]) ->filters([ SelectFilter::make('is_active') ->label('Status') ->options(IsActive::class) ->native(false), SelectFilter::make('location') ->label('Lokus') ->relationship('location', 'name') ->searchable() ->preload() ->native(false), TrashedFilter::make() ->native(false) ->visible(fn () => auth()->user()?->hasRole(RoleEnum::DEVELOPER->value)), ]) ->recordActions([ EditAction::make() ->modalWidth(Width::Large), DeleteAction::make(), ForceDeleteAction::make(), RestoreAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ ...DefaultBulkActions::make('Sublokus'), ]), ]) ->emptyStateIcon(Heroicon::OutlinedNumberedList) ->emptyStateHeading(fn () => CheerfulNotification::getByKey('locus.sub.empty_state_heading')) ->emptyStateDescription(fn () => CheerfulNotification::getByKey('locus.sub.empty_state')) ->defaultSort('created_at', 'desc') ->deferFilters(false) ->paginated([25, 50, 100, 'all']) ->deferLoading() ->groups([ Group::make('location.name') ->label('Lokus') ->collapsible(), ]) ->defaultGroup('location.name'); } public static function getPages(): array { return [ 'index' => ManageSubLocations::route('/'), ]; } public static function getRecordRouteBindingEloquentQuery(): Builder { return parent::getRecordRouteBindingEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } }