FilamentF
Filament2y ago
Mdk

Including a relationship form from a different Resource doesn't display repeater items in it

I'm trying to cut down on my duplicated code, so inside a OrderResource I created this method
public static function getProductsForm()
{
return [
Forms\Components\Repeater::make('orderProducts')
    ->relationship('orderProducts')
    ->schema([
        Forms\Components\Select::make('product_id')
            ->relationship('product', 'name',
                modifyQueryUsing: fn (Builder $query) => $query->enabled())
            ->live()
            ->searchable()
            ->preload()
            [....]
        ]),
Forms\Components\TextInput::make('discount')
    ->numeric()
    ->rules(['regex:/^\d{1,6}(\.\d{0,2})?$/'])
    ->minValue(0)
    ->suffix('€'),
Forms\Components\TextInput::make('total')
    ->label('Total')
    ->disabled()
    ->readOnly()
    ->dehydrated(false)
  ];
}

Calling it from the OrderResource itself works fine, but now I'm also adding it to a different resource, ShipmentResource
Forms\Components\Section::make()
    ->heading(__('Order informations'))
    ->relationship('order')
    ->headerActions([
        Forms\Components\Actions\Action::make('openShipment')
            ->label(__('View Order'))
            ->url(fn($record) => OrderResource::getUrl('edit', ['record' => $record->order->id]))
    ])
    ->schema([
        Forms\Components\Group::make()
            ->columnSpanFull()
            ->columns(2)
            ->schema(OrderResource::getOrderForm()),
        Forms\Components\Group::make()
            ->columnSpanFull()
            ->columns(2)
            ->schema(OrderResource::getProductsForm())
    ]),


Thing is, the order details are displayed fine, the discount and total as well, but the repeater is not showing at all (unless I make it non-disabled, then the add button appears)
Was this page helpful?