ExportAction getColumns from Service class

I’m having an issue trying to export data using ExportAction from a service class, InvoiceService, that generates columns from various models, plus several calculated columns. I am using an InvoiceObserver watching for an invoice to get created, at which point, it will generate a pdf, then generate a csv file in a format to be used to upload to various billing systems in what is called a Ledes file. I decided to use the observer with a separate InvoiceService class to separate the concerns.
<?php

namespace App\Observers;

use …

class InvoiceObserver implements ShouldHandleEventsAfterCommit
{
public function created($data): void
{
InvoiceService::createInvoicePdf($data);
InvoiceService::createLedes();
});
}
<?php

namespace App\Observers;

use …

class InvoiceObserver implements ShouldHandleEventsAfterCommit
{
public function created($data): void
{
InvoiceService::createInvoicePdf($data);
InvoiceService::createLedes();
});
}
the InvoiceEvent model (belongsTo and account) contains all of the items included on the invoice (rows of records included on the invoice) and is periodically updated during the month adding time entries, costs, etc. the invoice model gets created at the end of the month, and captures all of the InvoiceEvent(s) for an account. the invoice model only contains a date, name, account_id, status, and total columns (with timestamps). The invoice is created first, then run updates on the InvoiceEvent model to add the invoice_id to the InvoiceEvent model, capturing all unbilled items. It is at that point that we have all the records from InvoiceEvent(s) to be used for the pdf and ledes functions below. In addition, a few other properties get filled (like totals, tax, etc), then the pdf is run. All the data gets filled into the invoice and this method works great. The problem is with the ExportAction for the Ledes csv file. In the InvoiceService class, I have the following:
<?php
namespace App\Services;

use …
private static Collection $events;

class InvoiceService
{
public static function createInvoicePdf($data)
{
// grab all the invoice items from the InvoiceEvents table
// invoice items gets put into an $events collection.
// create the PDF
}

public static function createLedes()
{
ExportAction::make(self::$events) // also tried passing an array of records here, created_at is one of the keys, see below in exporter
->exporter(InvoiceEventExporter::class)
->columnMapping(false);
}

}
<?php
namespace App\Services;

use …
private static Collection $events;

class InvoiceService
{
public static function createInvoicePdf($data)
{
// grab all the invoice items from the InvoiceEvents table
// invoice items gets put into an $events collection.
// create the PDF
}

public static function createLedes()
{
ExportAction::make(self::$events) // also tried passing an array of records here, created_at is one of the keys, see below in exporter
->exporter(InvoiceEventExporter::class)
->columnMapping(false);
}

}
<?php

namespace App\Filament\Exports;



class InvoiceEventExporter extends Exporter
{

protected static ?string $model = InvoiceEvent::class; // not sure if this is correct, tried InvoiceService::class also
protected Export $export;

public static function getColumns(): array
{
ExportColumn::make(‘created_at’)
->label(‘INVOICE_DATE’),

}
<?php

namespace App\Filament\Exports;



class InvoiceEventExporter extends Exporter
{

protected static ?string $model = InvoiceEvent::class; // not sure if this is correct, tried InvoiceService::class also
protected Export $export;

public static function getColumns(): array
{
ExportColumn::make(‘created_at’)
->label(‘INVOICE_DATE’),

}
No jobs get generated, no csv file is created. Nothing is written to the laravel.log. I cannot figure out why nothing is happening and been stumped for hours with trial and error and code diving, but this is beyond my expertise at this point. By way of side notes, the InvoiceService class generates columns not found in the invoice (or InvoiceEvent) model. Do I still need to declare the $model property? I tried to set the $model property to the InvoiceService::class but that did not seem to work either. The exporter class needs to receive all the data from the InvoiceService and use the array values in the getColumns method of the Exporter, however, it is not working as attempted (by passing an array or the collection object in). I’m using the built in Exporter available from filament and am on version 3.2.66. Any help is greatly appreciated.
0 Replies
No replies yetBe the first to reply to this messageJoin