All media (pdfs) table and how to make an open and download buttons for each record (for each pdf)

Hello. My users add several pdfs in several pages and now I want to make a resource for ALL PDFS, where every record is one only PDF. I already have that, coming from the table with name "media", but I cannot add a link or button to open the file in new tab and and another one for download. I am using Spatie Media Library but cannot find the right help for this. I really have all the information I need in that file called "media" I have tried this
TextColumn::make('name')
->label(__('name'))
->searchable()
->url(function (Get $get) {
$path=storage_path();
$ModelId= ($get('model_id')) ?? $get('model_id');
$name=($get('file_name')) ?? $get('file_name');
return $path . '/' . $ModelId . '/' . $name;
})
->openUrlInNewTab()
->sortable(),
TextColumn::make('name')
->label(__('name'))
->searchable()
->url(function (Get $get) {
$path=storage_path();
$ModelId= ($get('model_id')) ?? $get('model_id');
$name=($get('file_name')) ?? $get('file_name');
return $path . '/' . $ModelId . '/' . $name;
})
->openUrlInNewTab()
->sortable(),
but I get the error: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization for the first line with $get I have also tried an Action button like this:
Tables\Actions\Action::make(
__('Download'),
function (Get $get, Media $record) {
$path=storage_path();
$ModelId= ($get('model_id')) ?? $get('model_id');
$name=($get('file_name')) ?? $get('file_name');
return $path . '/' . $ModelId . '/' . $name;
}
)->icon('heroicon-o-arrow-down-tray')
Tables\Actions\Action::make(
__('Download'),
function (Get $get, Media $record) {
$path=storage_path();
$ModelId= ($get('model_id')) ?? $get('model_id');
$name=($get('file_name')) ?? $get('file_name');
return $path . '/' . $ModelId . '/' . $name;
}
)->icon('heroicon-o-arrow-down-tray')
but nothing seems to happen. Could anybody please give me hint of the right approach for this? Thanks a lot.
2 Replies
Albert Lens
Albert LensOP14mo ago
Leandro Ferreira gave a solutions here for the url link. https://discord.com/channels/883083792112300104/1154117866774335508/1154233296918696046 Anyway, I would like to have two action buttons for every record in the table: open PDF and DOWNLOAD pdf. Any ideas of how to put those as action buttons in table? Tks
lordjackson
lordjackson11mo ago
Thanks for your tip @Albert Lens, it also helped me!
Want results from more Discord servers?
Add your server