schema([ Section::make('') ->schema([ Forms\Components\TextInput::make('name') ->required() //->citext('name') ->placeholder('Scan the valid name') ->autofocus(true) ->unique(ignoreRecord: true) ->columnSpanFull() ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { $companyId = $get('name'); // Ensure `linestop_id` is not cleared if (!$companyId) { $set('cNameError', 'Scan the valid name first.'); return; } else { $set('cNameError', null); } }) ->extraAttributes(fn ($get) => [ 'class' => $get('cNameError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('cNameError') ? $get('cNameError') : null) ->hintColor('danger'), ]) ->columns(2), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('id') ->label('ID') ->numeric() ->sortable(), Tables\Columns\TextColumn::make('name') ->sortable(), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable(), Tables\Columns\TextColumn::make('updated_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('deleted_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ Tables\Filters\TrashedFilter::make(), ]) ->actions([ Tables\Actions\EditAction::make(), Tables\Actions\ViewAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), Tables\Actions\ForceDeleteBulkAction::make(), Tables\Actions\RestoreBulkAction::make(), ]), ]) ->headerActions([ ImportAction::make() ->importer(CompanyImporter::class) ]); } public static function getRelations(): array { return [ PlantsRelationManager::class, ]; } public static function getPages(): array { return [ 'index' => Pages\ListCompanies::route('/'), 'create' => Pages\CreateCompany::route('/create'), 'view' => Pages\ViewCompany::route('/{record}'), 'edit' => Pages\EditCompany::route('/{record}/edit'), ]; } public static function getEloquentQuery(): Builder { return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } }