F
Filamentβ€’15mo ago
Diogo Pinto

Action shows view with nested actions?

Hey guys, how are you? How would you approach creating an action that is a livewire component by itself? Meaning, that when you click it renders a dynamic view with actions nested? I've used:
->modalContentFooter(fn ($record) => view(
'filament.actions.media-browser',
['documents' => $record->getDocuments()],
)),
->modalContentFooter(fn ($record) => view(
'filament.actions.media-browser',
['documents' => $record->getDocuments()],
)),
this returns an array, and in the blade file I user a foreach... but I want to be able to click an array item and when I click it, it renders a modal with something. Thank you so much!
5 Replies
Patrick Boivin
Patrick Boivinβ€’15mo ago
I think I don't understand the nested actions part... do you have something like a mockup of the UI you're trying to create?
Diogo Pinto
Diogo PintoOPβ€’15mo ago
@Patrick Boivin sorry for the delay, and thank you for your answer! I don't have it at the moment but what I was trying to achieve: - On a infolist I have an action that says "Browse Media" - slide over action - When I open it it shows an upload form above and I wanted to display a table below with all the currently uploaded media - When I click the media, it opens a modal with the file (clickable row action) I don't know if this makes sense, but I'm having trouble defining an action that may be able to do this
Patrick Boivin
Patrick Boivinβ€’15mo ago
Which part are you stuck on? Do you have the slideover action working?
Diogo Pinto
Diogo PintoOPβ€’15mo ago
I think I got it @Patrick Boivin... I ended up using a relation manager with the media model πŸ™‚ (spatie medialibrary)... In the table schema:
Tables\Columns\TextColumn::make('name')
->action(
Tables\Actions\Action::make('preview')
->modalContentFooter(
fn ($record) => view(
'filament.actions.media-browser',
['document' => $record],
)
)
->modalSubmitAction(false)
->extraModalFooterActions(fn ($record): array => [
Tables\Actions\Action::make('download')
->action(fn ($record) => response()->download($record->getPath(), $record->name . '.' . pathinfo($record->getPath(), PATHINFO_EXTENSION))),
])
)
->icon('heroicon-o-magnifying-glass'),
Tables\Columns\TextColumn::make('name')
->action(
Tables\Actions\Action::make('preview')
->modalContentFooter(
fn ($record) => view(
'filament.actions.media-browser',
['document' => $record],
)
)
->modalSubmitAction(false)
->extraModalFooterActions(fn ($record): array => [
Tables\Actions\Action::make('download')
->action(fn ($record) => response()->download($record->getPath(), $record->name . '.' . pathinfo($record->getPath(), PATHINFO_EXTENSION))),
])
)
->icon('heroicon-o-magnifying-glass'),
And in the view file:
@if ($document->mime_type === 'application/pdf')
<embed src="{{ $document->getUrl() }}" width="100%" height="700px" type="application/pdf">
@else if
........
@if ($document->mime_type === 'application/pdf')
<embed src="{{ $document->getUrl() }}" width="100%" height="700px" type="application/pdf">
@else if
........
Thank you for your input though πŸ™‚ If you click the row it previews the file (in the blade file) and inside that action there is an action to download (extraModalFooterActions)
Patrick Boivin
Patrick Boivinβ€’15mo ago
Nice!
Want results from more Discord servers?
Add your server