Placeholder with record data and link

I'm trying to use both HtmlString and a closure with the model but I'm not sure what the right syntax should be. This is the code I've got:
Placeholder::make('name')
->content(fn(Application $application): string => $application->applicant->fullName)
->url(fn(Application $application): string => route('profile', ['id' => $application->user_id, 'page' => 'payments']))
Placeholder::make('name')
->content(fn(Application $application): string => $application->applicant->fullName)
->url(fn(Application $application): string => route('profile', ['id' => $application->user_id, 'page' => 'payments']))
I realize that ->url is not a method on Placeholder elements, but I don't see how to use the HtmlString with the closure to get the content. Thank you!
3 Replies
DrByte
DrByte6mo ago
In "most" fields, passing certain variable names to the closure will automatically resolve and inject the specified object into the closure. It's based on the variable name, not the model. See https://filamentphp.com/docs/3.x/forms/advanced#form-component-utility-injection
DrByte
DrByte6mo ago
However, that said, since things get sanitized for output, if you generate a URL it's probably going to be url-encoded, not clickable. For example, if your Panel is named foo then this will generate the URL and stick it in the placeholder as plain text:
Forms\Components\Placeholder::make('something')
->content(fn ($record)=> route('filament.app.resources.foo.view', ['record' => $record->id])
Forms\Components\Placeholder::make('something')
->content(fn ($record)=> route('filament.app.resources.foo.view', ['record' => $record->id])
gmgarrison
gmgarrison5mo ago
Got it - thank you!