How to modify CRUD data saved to action_events table in Laravel Nova
I have a simple problem that I cannot find a simple solution to. I am using v2 of Laravel Nova and need a way to modify two fields:
amount_due and amount_paid
All I need to do is divide them by 100 before saving them to the action log (to the json columns 'original' and 'changes' of the action_events table). E.g. 1500 formats as 15.00
The Actionable trait is used on my model, so that the CRUD functionality is logged to each Nova Payment resource.
class Payment extends Model
{
use Actionable;
......
I have tried to set up a listener to the ActionEvent action, so that it gets modified like so... but this doesn't work.
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
ActionEvent::class => [FormatPaymentAmountLogData::class],
...
class FormatPaymentAmountLogData
{
public function handle($event)
{
$actionEvent = $event->actionEvent;
$data = $actionEvent->data;
if (isset($data['amount_paid'])) {
$data['amount_paid'] = $data['amount_paid'] / 100;
}
if (isset($data['amount_due'])) {
$data['amount_due'] = $data['amount_due'] / 100;
}
return $actionEvent->data = $data;
}
}
I can't find any documentation on this that does something this simple. Does anybody have a way I can fix this?
Please or to participate in this conversation.