-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logs collection does not update upon deleting an object #27
Comments
Hi @abodnar , Please show me your model. |
Here is my model.
|
Hi There, I tested here and it's all right |
Yes, it is still not returning a log for the deletion of the object. |
@abodnar You are with the latest version? |
I am on version 2.1.7 |
Hi @abodnar , I tried many ways and can not seem simulate the error. I created this example https://github.com/anteriovieira/laravel-auditing-deletion for you to help me find the error. The application is working, please test. I await your reply. Thank you. |
So I looked at what you did compared to how I was using the logs. The difference I found is that I'm using $obj->logs versus using \OwenIt\Auditing\Log::all()->toArray() to get the logs. When I use your method to get the logs, I definitely have the deletion log. Wouldn't this get all logs for any changed items? So the problem I see is that the object itself is not having it's logs property updated when a deletion is done. |
Hi @abodnar , It is not possible to obtain the logs of the object excluded, because at that time it no longer exists. For the logs that record you'll have to use another implementation. Example: /* Get user */
$userCreated = \App\User::all()->last();
$log = new OwenIt\Auditing\Log();
/* Delete user */
$userCreated->delete();
/* Get logs */
dd( $log->where('owner_type', App\User::class)->get() );
// and another implementations ... |
While working on some code where I'm using this package, I found that if I delete an object the log collection does not update to contain a log entry for the deletion. This may be expected, but I wanted to be sure. I have soft deletes on my object, so maybe that has something to do with it. Though I do know it's logging the deleting in the logs table.
Also I found that I get an error when trying to use logs()->last().
BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::last()
The text was updated successfully, but these errors were encountered: