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.
3 Replies
MazeEzam
MazeEzam5mo 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-R3w ago
Did you managed to find a solution to this?