schema([ Forms\Components\TextInput::make('code') ->required() ->unique(ignoreRecord: true) ->minLength(6) ->autocapitalize('code'), Forms\Components\TextInput::make('hourly_quantity') ->required() ->numeric() ->minValue(1), Forms\Components\Textarea::make('description') ->required() ->columnSpanFull(), Forms\Components\Select::make('plant_id') ->relationship('plant', 'name') ->required() ->reactive() ->afterStateUpdated(fn ($set) => $set('block_id', null)), // Reset block_id when plant changes Forms\Components\Select::make('block_id') ->relationship('block', 'name') ->required() ->options(fn (callable $get) => \App\Models\Block::where('plant_id', $get('plant_id')) ->pluck('name', 'id') ->toArray() // Convert collection to array ) ->reactive(), // Ensures the dropdown updates when plant_id changes // Forms\Components\Select::make('plant_id') // ->relationship('plant', 'name') // ->required() // ->reactive(), // Forms\Components\Select::make('block_id') // ->relationship('block', 'name') // ->required() // ->options(fn (callable $get) => // \App\Models\Block::where('plant_id', $get('plant_id'))->pluck('name', 'id') // ) // ->reactive() // Updates dynamically when plant_id changes // ->afterStateUpdated(fn ($set) => $set('block_id', null)), // Reset block_id when plant_id changes Forms\Components\Select::make('line_id') ->relationship('line', 'name') ->required(), ]); } 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('hourly_quantity') ->numeric() ->sortable(), Tables\Columns\TextColumn::make('description') ->sortable(), Tables\Columns\TextColumn::make('line.name') ->sortable(), Tables\Columns\TextColumn::make('block.name') ->sortable(), Tables\Columns\TextColumn::make('plant.name') ->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(ItemImporter::class), ExportAction::make() ->exporter(ItemExporter::class), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListItems::route('/'), 'create' => Pages\CreateItem::route('/create'), 'view' => Pages\ViewItem::route('/{record}'), 'edit' => Pages\EditItem::route('/{record}/edit'), ]; } public static function getEloquentQuery(): Builder { return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } }