Support the ongoing development of Laravel.io →
Eloquent Configuration

Hello Guys!

I have some problems with the usage of Events and Listeners. I'm trying to make an Audit Log for my site and I tried to be elegant and use Events, but I ran into some interesting behaviour when passing an Eloquent object to the event.

For example I want to log that a Scope was deleted from the table (since I need to write some logic the Log:: is not an option)

$scope->delete(); event(new DatabaseModified($scope));

In the event I simply pass the Eloquent object

public function __construct($entry) { $this->entry = $entry; }

But after it I get 404 with No query results for model [App\Entities\Scope]. message.

I tested this and instead of passing the object the listener re-queries the DB and use the new object.

Why does this works like that?

What are my options for possible workaround?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Fauszt András fauszt Joined 30 Apr 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.