System of Log in Data Management System

2

I am developing a data management system in PHP Laravel 5 .

On this system I want to put a Logs System.

1 - Does Laravel have any library that facilitates this system?

2 - If Laravel does not have the best way to do such a system?

3 - How can I model the data in the database?

I thought of the following case:

User So-and-so (who) changed / created / deleted / forwarded (action) 11/2015 (when) .

And I thought of a simple table with the following columns:

ID_LOG
ID_USER
ACAO
DESCRICAO
DATA

Maybe the question is wide when I use the expressions 'what's the best way' or 'how can I do it'.

My main question is whether Laravel can make things easier for me.

    
asked by anonymous 17.11.2015 / 17:17

1 answer

2

What you will need to do these operations in Models is probably called Model Observers .

You can see some examples on the Laravel page.

link

class UserObserver {

    public function saving($model)
    {
        //
    }

    public function saved($model)
    {
        RegistrarLog::create([
            "observacao" => "Alterou um usuário",
            "id" => Auth::user()->id,
            "usuario_alterado_id" => $model->id
        ]);
    }

}

User::observe(new UserObserver);

Consequently, when you use the save or update method, you will automatically have the system enter the data of the UserObserver::saved method.

Yet another thing that can be done is to use Model Events .

See them on the page:

link

They are creating, updating, saving, and deleting. The names already suggest what each will do in each action in the model.

The examples shown show that these methods must be defined in the observed model (which you will want to automatically log a log).

    
17.11.2015 / 17:30