Nisanth Nisanth - 1 year ago 106
PHP Question

How to make a log while insert , update, delete a record into DataBase Tables in MYSQL Using PHP

I want to make a log details for my database while a record insert into any table and update any table and delete any record from an table in MYSQL - PHP. Please give me some ideas.

Answer Source

You've used laravel tag, so I assume you want to find a 'Laravel way' to do it.

The best practice is to use Eloquent Events.

Each time when Laravel will hit the DB, it will try to run some of these events: creating, created, updating, updated, saving, saved, deleting, deleted, restoring, restored

-ing events are used before hitting DB, -ed events are used right after hitting DB.


public function boot()
    User::created(function () {
        Log::info('User was just created successfully');