F
Filamentβ€’13mo ago
rg.block

Placeholder content based on conditional logic based on value from another component?

Is it possible to set the content of a Placeholder with conditional logic if the value of another component or even the value of a property I am using on a ->mountUsing is equal to something? In more detail, I have a table and I am using Action to open a modal window. The modal has a few TextInputs whose values are being set with ->mountUsing, and then I have a Repeater using ->relationship(), and the repeater has a Placeholder and other components inside. I would like the content of the Placeholder to be something if the value of one of the mounted TextInputs is 1, something else if it is 2, and so on. The code for my Action is: Action::make('viewPackage') ->label('View') ->mountUsing(fn (Forms\ComponentContainer $form, Package $record) => $form->fill([ 'package_name' => $record->name, 'number_of_documents' => $record->number_of_documents, 'state_name' => $record->jurisdiction->state->name, 'jurisdiction_name' => $record->jurisdiction->name, 'provider' => $record->provider_id, ])) ->icon('heroicon-s-eye') ->color('success') ->visible(fn ($record) => $record->status_id === 3) ->action(function (Package $record, array $data): void { $record->package()->associate($data['packageId']); $record->save(); }) Where 'provider' => $record->provider_id, is the value I need to be used on the Placeholder logic. Right now my Placeholder code is just setting the value like: Placeholder::make('document_type_name')->content(fn ($record) => $record?->documentTypePrimary->name), which works when the provider is 1, but I am not evaluating that, so I would like to check for whatever value the provider is and then set $record?->documentTypePrimary to be ->documentTypeSecondary, ->documentTypeTernary, etc. Is that something that can be done here, or perhaps I am just overcomplicating things here? I have tried using a function but I just cant find a way to access the value of provider I am adding the gist to the entire action code here for full reference. https://gist.github.com/rgut13rrez/e18fc9aafb72e26e7c156ea2c42653db
Gist
packages.php
GitHub Gist: instantly share code, notes, and snippets.
2 Replies
ZedoX
ZedoXβ€’13mo ago
fn ($record, $get) => $get('provider') ?
rg.block
rg.blockβ€’13mo ago
Ok, that helped me think through it, and what worked for me was: Placeholder::make('document_type_name')->content(function ($record, $get) { // Depending on provider, select the correct document type $provider = $get('../../provider'); if ($provider === 1) { return $record?->documentTypePrimary->name; } else if ($provider === 2) { return $record?->documentTypeSecondary->name; } }), The important part being '../../provider' to access it outside the repeater