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('No.') ->label('No.') ->getStateUsing(function ($record, $livewire, $column, $rowLoop) { $paginator = $livewire->getTableRecords(); $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; return ($currentPage - 1) * $perPage + $rowLoop->iteration; }), Tables\Columns\TextColumn::make('name') ->label('Company') ->alignCenter() ->sortable() ->searchable(), Tables\Columns\TextColumn::make('created_at') ->label('Created At') ->dateTime() ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('updated_at') ->label('Updated At') ->dateTime() ->alignCenter() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('deleted_at') ->label('Deleted At') ->dateTime() ->alignCenter() ->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() ->label('Import Companies') ->color('warning') ->importer(CompanyImporter::class) ->visible(function() { return Filament::auth()->user()->can('view import company'); }), ExportAction::make() ->label('Export Companies') ->color('warning') ->exporter(CompanyExporter::class) ->visible(function() { return Filament::auth()->user()->can('view export company'); }), ]); } 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, ]); } }