F
Filament16mo ago
RMH

Trying to create bulk action to print invoices

I am trying to create a bulk action to print invoices/challans. I created a simple action with the help of https://github.com/chandraauliatama/InvoiceCreator and while creating a bulk action I am trying to do the same thing but instead of sending a single challan I am (doing something stupid maybe) trying to send a collection of challan in route.
Tables\Actions\BulkAction::make('Print Challans')
->icon('heroicon-o-printer')
->url(fn (Collection $records): string => route('print.challans', $records))
->openUrlInNewTab(),
Tables\Actions\BulkAction::make('Print Challans')
->icon('heroicon-o-printer')
->url(fn (Collection $records): string => route('print.challans', $records))
->openUrlInNewTab(),
the route is Route::get('challans/print', [PrintController::class, 'many'])->name('print.challans'); and the function in controller is
public function many(Collection $challans)
{
$printDate = Carbon::now()->format('jFY');
$fileName = "challans_{$printDate}";

return view('print.many', compact('challans', 'fileName'));
}
public function many(Collection $challans)
{
$printDate = Carbon::now()->format('jFY');
$fileName = "challans_{$printDate}";

return view('print.many', compact('challans', 'fileName'));
}
And the list page does not load. it gives me TypeError
App\Filament\Resources\ChallanResource::App\Filament\Resources\{closure}(): Argument #1 ($records) must be of type Illuminate\Database\Eloquent\Collection, null given, called in D:\school\eduf\vendor\filament\support\src\Concerns\EvaluatesClosures.php on line 35
App\Filament\Resources\ChallanResource::App\Filament\Resources\{closure}(): Argument #1 ($records) must be of type Illuminate\Database\Eloquent\Collection, null given, called in D:\school\eduf\vendor\filament\support\src\Concerns\EvaluatesClosures.php on line 35
Is there any other way to do it? A bulk action for printing
GitHub
GitHub - chandraauliatama/InvoiceCreator
Contribute to chandraauliatama/InvoiceCreator development by creating an account on GitHub.
2 Replies
Patrick Boivin
Patrick Boivin16mo ago
I think you can probably do this with a redirect instead, something like this:
->action(function (Collection $records) {
$record_ids = $records->pluck('id')->join(',');
return redirect(route('print', ['record_ids' => $record_ids]));
})
->action(function (Collection $records) {
$record_ids = $records->pluck('id')->join(',');
return redirect(route('print', ['record_ids' => $record_ids]));
})
RMH
RMHOP16mo ago
Thanks, it worked
Want results from more Discord servers?
Add your server