I am creating my custom activity logs and everything works fine except the part that works with the Livewire. My product edit page is whole made with the livewire (10 components separated) and when I try to make some changes (send update method request) I get the black popup like the one when we dd something, just without any messages inside. Since the log making is the last part of the save method in LW, product gets saved and all the code is running fine except the log making.
My code for making the log is in the model as a static method:
// Helper methods
public static function log($message, $model_id, $model_type, $query_info, $view_route = '')
{
// Check if something is created by the System or by the logged user
if (Auth::check()) {
$author = Auth::user()->id;
} else {
$author = 'System';
}
self::create([
'user_id' => $author,
'loggable_id' => $model_id,
'loggable_type' => $model_type,
'action_executed' => $message,
'view_route' => $view_route,
'query_info' => json_encode($query_info),
'description' => 'Automated system log',
'executed_at' => now()
]);
}
And this is how it is called:
Changelog::log('Product updated ID ' . $this->product->id, $this->product->id, $this->model,DB::getQueryLog(), 'admin.product.view');
Am I missing something?
I have tried to dd line by line to see where it gets broken, and seems like everything is fine until code reaches self::create
in the model.
FIXED
Hello guys, so if anyone is working on something like this, the issue was with fetching the exceptions like wrong/missing route, etc.
Usually, when you catch exceptions it will have "previous" since I did not know that some exceptions can come without it, and that was the issue that caused errors.
if($exception)
{
Changelog::log($exception->getMessage(), null, get_class($exception->getPrevious()), DB::getQueryLog(), '');
}
Here is the code I am using just in case you are wondering how can you catch it ^^