mercredi 14 septembre 2016

Advanced Logging System Using Laravel

Hello I have a little dilemma, I need to create a logging system on an application that I've built that basically just logs users different activities such as "Created/Updated/Deleted" etc. I know this can be accomplished by doing something like the following

public function deleteUser($user_id)
{

    // Delete the user
    User::where('id', $user_id)->delete();

    // Log what action took place
    $log = new Log();
    $log->name   = $current_username;
    $log->action = 'Deleted User';
    $log->time   = Carbon::now();
    $log->save();

}

But using this method means that not only do i have to go to each event i want logging and add this code but any methods i make in the future will need to have this again.

My question is, is there any way to achieve logging more.. dynamically? I can't think of the appropriate logic.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire