schema([ Section::make('') ->schema([ Forms\Components\TextInput::make('code') ->required() ->alphaNum() ->unique(ignoreRecord: true) ->minLength(3) ->placeholder('Scan the valid code') ->autofocus(true) ->autocapitalize(autocapitalize: 'characters') ->columnSpan(1) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { $code = $get('code'); if (!$code) { $set('lsCodeError', 'Scan the valid code.'); return; } else { if (strlen($code) < 3) { $set('lsCodeError', 'Code must be at least 3 digits.'); return; } else if (!preg_match('/^[a-zA-Z0-9]{3,}$/', $code)) { $set('code',null); $set('lsCodeError', 'Alpha-numeric only allowed.'); return; } $set('lsCodeError', null); } }) ->extraAttributes(fn ($get) => [ 'class' => $get('lsCodeError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('lsCodeError') ? $get('lsCodeError') : null) ->hintColor('danger'), Forms\Components\TextInput::make('reason') ->required() ->placeholder('Scan the valid reason') ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { $reason = $get('reason'); if (!$reason) { $set('lsReasonError', 'Scan the valid reason.'); return; } else { $set('lsReasonError', null); } }) ->extraAttributes(fn ($get) => [ 'class' => $get('lsReasonError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('lsReasonError') ? $get('lsReasonError') : null) ->hintColor('danger') ->columnSpan(['default' => 1, 'sm' => 2]), ]) ->columns(['default' => 1, 'sm' => 3]), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('id') ->label('ID') ->numeric() ->sortable(), Tables\Columns\TextColumn::make('code') ->sortable(), Tables\Columns\TextColumn::make('reason') ->sortable(), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), 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\ViewAction::make(), Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), Tables\Actions\ForceDeleteBulkAction::make(), Tables\Actions\RestoreBulkAction::make(), ]), ]) ->headerActions([ ImportAction::make() ->importer(LineStopImporter::class), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListLineStops::route('/'), 'create' => Pages\CreateLineStop::route('/create'), 'view' => Pages\ViewLineStop::route('/{record}'), 'edit' => Pages\EditLineStop::route('/{record}/edit'), ]; } public static function getEloquentQuery(): Builder { return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } }