How to get selected records in PDF using filament 3
if there are 100 records from that few selected records pdf i need how to make that possible in filament 3
40 Replies
would you like to get the records from the table?
Could you explain what are you trying to do?
Yes i want to get records from the table i will select the records checkbox and need one button to download PDF of that selected records
@Leandro Ferreira you will get more clarity with this image
@Leandro Ferreira Sorry to bother you but if you can suggest how to resolve this its urgent for me
ahh ok, inject
$livewire
and try getSelectedTableRecords
I have tried this with livewire but its not working. as i have to work with loop as can get single record
in my application i am able to download all the records PDF but not been able to download selected records PDF.
if i want to download single record PDF that is also working
having issue with selected records
Multiple PDF's ? Or one containing all the records ?
one containing all the records
i want to created a product catalog.
so when administrator select few records he can generate single PDF contains all selected records
hum, I think you can use bulk action in the table header actions to get the selected records:
below its the code from which i am generating all the records PDF
$product = Products::orderBy('position','asc')->get();
$pdf = pdf::loadView('catalogpdf',array('product' => $product))->setPaper('letter');
return $pdf->download('catalog.pdf');
and i am using this action
Tables\Actions\Action::make('Download Pdf')
->icon('heroicon-o-code-bracket-square')->url('/pdf')
@Leandro Ferreira please help me if you can as i am stuck in this from last 10 days each functionlity is done just this thing is incomplete
Did you try bulk action as I said?
yes i have tried that let me show you that what is the issue in that code
@Leandro Ferreira i need to access like below code which i have used to delete image of selected records
function (Collection $records) {
$records->each(function (Products $record) {
if ($record->image) {
Storage::disk('public')->delete($record->image);
}
});
})
and for all selected records in one PDF i need to use route to transfer that selected array
we can get selected records array with the help as you suggested $selected = $livewire->getSelectedTableRecords(); but again its using livewire so problem is not getting sorted out
Would you like to generate a single PDF per record, right?
Why not create a zip containing all the PDFs??
i want all the selected records in one single PDF
not single pdf per record
You have the selected records, you can build a pdf with them
i am not been able to build that what i am saying....
if you have any solution to build a single PDF for selected records do send me
@Leandro Ferreira check this image and red box which i have mark you will come to know that i mean to say
Ok, just to clarify, this is not a Filament issue. You can get the selected records as your first question
you having trouble converting data to PDF?
this is the filament issue only how can i get selected records array to pass in route
what output did you get when you do dd($outputSelected)?
if you get the selected output then you can just convert them into one PDF
@Lucky0 $selected = $livewire->getSelectedTableRecords(); through this i can get selected records but i can use the records one by one. i cannot pass the array to route. and livewire is not allwowing to generate PDF as i am using domPDF package
use this as reference: https://laraveldaily.com/post/laravel-dompdf-generate-simple-invoice-pdf-with-images-css
all i can help is with the logic. hopefully.. what you want is to get list of that selected items. right? try to output it in a page see if its displaying all the items. then you use that page and convert it to pdf.. not sure if this will work.. havent tried it myself, but you never know, unless you try..
@Lucky0 i agree with you this working but this thing work for a single record not working for selected records
i have already tried this but this does not help in my senario
can you share you code here, please?
@Lucky0
This code i am using for generating all records PDF and its working fine
/* Code in controller function start /
$product = Products::orderBy('position','asc')->get();
$pdf = pdf::loadView('catalogpdf',array('product' => $product))->setPaper('letter');
return $pdf->download('catalog.pdf');
/ Code in controller ends */
and i am using this action
Tables\Actions\Action::make('Download Pdf')
->icon('heroicon-o-code-bracket-square')->url('/pdf')
can i see your catalogpdf code?
i am getting selected records with the help of this in bulk action
Tables\Actions\DeleteBulkAction::make()->before(
function (Collection $records) {
$records->each(function (Products $record) {
// i can get single record through this
});
}),
])
with this i am able to access single record i cannot pass an array to routes
Acion in filament resource
Tables\Actions\Action::make('Download Pdf')
->icon('heroicon-o-code-bracket-square')->url('/pdf')
Routes
Route::any('/pdf', [ProductsController::class, 'index'])->name('products.index');
// Function in contorller
public function index()
{
$product = Products::orderBy('position','asc')->get();
$pdf = pdf::loadView('catalogpdf',array('product' => $product))->setPaper('letter');
return $pdf->download('catalog.pdf');
}
pass the record ids to your route
$records->pluck('id')->implode(',')
how to pass that array to route its not possible
this is a string, not array
okay let me try if that can work
will get back to you with this
pass the ids as I said and get the ids in your class
$ids = str(request()->ids)->explode(',');
Solution
try this:
with this you dont have to use controller
@Lucky0 will try this and get back to you once it works
hope both the technique suggested works
will get back to you within an hour
this one work. i tried it
have you use domPDF ?
i used this
this questions was asked more then once. should have tried searching...
@Lucky0 Problem is resolved as per your suggestion
Thank you very much for a great help
@Leandro Ferreira Thank you for your support