Data Management System Log System

Asked

Viewed 1,123 times

2

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

In this system I want to put a Logs.

1 - Laravel has some library that facilitates this system ?

2 - If Laravel doesn’t have the best way to make a system like this ?

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

I thought the following case:

User Fulano (whosoever) changed/created/deleted/forwarded (action) called ID 43 (what) on the date 17/11/2015 (when).

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

ID_LOG
ID_USER
ACAO
DESCRICAO
DATA

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

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

  • No monolog coming along?

  • So I don’t know how to use this. But you have this folder in the folder vendor. I don’t know what your use is.

  • May be a start => http://answall.com/a/72844/91

  • The Laravel page can help you http://laravel.com/docs/4.2/errors

  • @Taopaipai, had a system that I did it. Only I did only for "strange accesses", ie only when I had error 500. You can do it with the Model events. For example saving, updating, who will identify that the model had a rescue event.

  • @rray. But it is possible to write to the database instead of a file .log using the Monolog ?

Show 1 more comment

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.

http://laravel.com/docs/4.2/eloquent#model-Observers

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 method save or update, you will cause the system to automatically enter the method data UserObserver::saved.

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

See them on the page:

http://laravel.com/docs/4.2/eloquent#model-Events

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

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

  • 1

    Nice going there, Laravel :D

  • I never used, kkkkkkkkkkkkkkkkkkk.

  • If it’s from the basement it should work :D It’s there to make life easier for people.

  • Soon I’ll make that scheme.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.