Export Action - Lifecycle Hooks

Hi All Ok, so I am using the prebuilt export action and I would like to update certain values in the DB for the rows that are exported. i.e. status Draft - Exported. Couldn't see anything in the Docs, Is there a lifecycle hook I can use here or is there a better way to tackle this? Thanks in advance.
6 Replies
MazeEzam
MazeEzamOP10mo ago
Thanks but I believe this is to format the output of the export column value? I want to update the rows inside the Database, on a successful export, specifically a column called Status. I want to know if that rows has already been exported. I did try this but this overrode the export action.
ExportAction::make('Export')
->exporter(AdjustmentExporter::class)
->formats([
ExportFormat::Xlsx,
ExportFormat::Csv,
]),
// Feature for later Status update from draft to exported

->action(function(){

$custid = $this->getOwnerRecord()->bundle_uuid;
$date = $this->getOwnerRecord()->next_review_date;

Adjustment::statusUpdate($custid,$date);
})
ExportAction::make('Export')
->exporter(AdjustmentExporter::class)
->formats([
ExportFormat::Xlsx,
ExportFormat::Csv,
]),
// Feature for later Status update from draft to exported

->action(function(){

$custid = $this->getOwnerRecord()->bundle_uuid;
$date = $this->getOwnerRecord()->next_review_date;

Adjustment::statusUpdate($custid,$date);
})
Code from Adjustment Model
public static function statusUpdate($custid,$date){
$rows = Adjustment::where('bundle_cust_id', $custid)
->where('review_date' , $date)
->where('status', 'draft')
->get();

foreach ($rows as $row){
Adjustment::where('id', $row->id)
->update(['status' => 'Exported']);
}
// dd($rows);

}
public static function statusUpdate($custid,$date){
$rows = Adjustment::where('bundle_cust_id', $custid)
->where('review_date' , $date)
->where('status', 'draft')
->get();

foreach ($rows as $row){
Adjustment::where('id', $row->id)
->update(['status' => 'Exported']);
}
// dd($rows);

}
I was hoping there may have been lifecycle hooks so I call the statusUpdate method once the rows had been exported
Wojtek-R
Wojtek-R7mo ago
Did you managed to find a solution to this?
David | Fortune Validator
Keen to know if you ever managed this ?
Kenneth Sese
Kenneth Sese5mo ago
@David | Fortune Validator Should be possible by overriding the handle method of the ExportCsv class as it loops through processing the records:
foreach ($query->find($this->records) as $record) {
try {
$csv->insertOne(($this->exporter)($record));

// your logic here

$successfulRows++;
} catch (Throwable $exception) {
$exceptions[$exception::class] = $exception;
}

$processedRows++;
}
foreach ($query->find($this->records) as $record) {
try {
$csv->insertOne(($this->exporter)($record));

// your logic here

$successfulRows++;
} catch (Throwable $exception) {
$exceptions[$exception::class] = $exception;
}

$processedRows++;
}
Take a look at this link for how to bind and override: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/export#customizing-the-export-job
David | Fortune Validator
Thank you. I’ll try it out
Want results from more Discord servers?
Add your server