Show file uploaded in Infolist
Hi. My forms uploads a PDF to the storage. Is there a way to show a component in an Infolist and download the file?
Thanks
Solution:Jump to solution
Oops, I managed to solve it using Custom entries.
https://filamentphp.com/docs/3.x/infolists/entries/custom
My view:...
8 Replies
I would probably do it with a custom entry, you will get access to the record and can use the Laravel storage helpers for download buttons and such: https://filamentphp.com/docs/3.x/infolists/entries/custom
Simplest for is probably a TextEntry with a
->url()
But what if it is an array with multiple attachments? I tried but I couldn't.
If it's an array, you can use a callback that get's passed the state:
->url(fn ($state) => )
Exactly, that's what I tried.
TextEntry::make('attachment')
->url(fn ($state) => url('storage/'.$state))
->listWithLineBreaks(),
ErrorException
Array to string conversion
I also tried like this
TextEntry::make('attachments')
->url(function ($state) {
foreach ($state as $attachment) {
return url('storage/'.$attachment);
}
})
->listWithLineBreaks(),
But it always shows only the first attachment.
->url()
might not support array then, sorry.Solution
Oops, I managed to solve it using Custom entries.
https://filamentphp.com/docs/3.x/infolists/entries/custom
My view:
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry">
<div>
@foreach($getState() as $state)
<p><a href="{{ url('storage/'.$state) }}" title="Download">{{ $state }}</a></p>
@endforeach
</div>
</x-dynamic-component>