Eloquent Model Events within Laravel integration

Observed behavior

When creating or updating records via Forest Admin’s Laravel integration, I’ve observed that Eloquent model events (such as creating, created, updating, updated) are not being fired. This behavior was identified after implementing custom logic within these model events which did not execute as expected during create/update operations initiated from Forest Admin’s UI.

Expected behavior

I expect that when records are created or updated through Forest Admin, all relevant Eloquent model events should be triggered.

Upon further investigation, it appears that Forest Admin’s integration utilizes the Laravel Query Builder for direct database operations, specifically through methods like insertGetId($data) for creating records, which bypasses the Eloquent model layer. This approach prevents Eloquent model events from being triggered. In my situation, I have some field values which need to be generated at create time (whether created via Forest or via my Laravel app).

Context

  • Project name: CNProject
  • Team name: Operations
  • Environment name: Development
  • Agent (forest package) name & version: forestadmin/laravel-forestadmin:3.0.1
  • Database type: postgres
  • Recent changes made on your end if any: none

Hi @ben_a, and welcome to our community :wave:.

Currently the agent PHP doesn’t support the triggereing of eloquent events.
I’ve just created a ticket on our dashboard and I’ll get back to you as soon as we’ve added it.
For the moment, you can use the hooks decorator to get the same behavior.
Here’s the documentation of hooks decorator.

1 Like

Hi,

I’ve just released a new version of the agent that includes support for eloquent events.

You can run the following command to update all relevant packages.

composer update forestadmin/laravel-forestadmin forestadmin/php-datasource-customizer forestadmin/php-datasource-eloquent

Superb, thank you! I’ll give it a try.

Great, feel free to reopen a thread if you encounter any problems.