w1n78
417
5
Laravel

ideas to store record activity logs?

Posted 2 years ago by w1n78

i need to store data whenever a record is created, updated, deleted. my migration file is as follows

Schema::create('record_logs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')
                ->index()
                ->unsigned();
            $table->string('user_full_name');
            $table->string('user_email');
            $table->bigInteger('record_id')
                ->unsigned();
            $table->string('table_name')
                ->index();
            $table->string('record_action', 50)
                ->comment('created, updated, deleted')
                ->index();
            $table->text('record_before')
                ->nullable();
            $table->text('record_after')
                ->nullable();
            $table->string('environment', 50)
                ->nullable();
            $table->timestamps();
        });

no constraints or cascade actions needed. it just creates records in this table. i may need to query the table and display records that belong to the data being tracked. i'm using mysql database for the project and currently using the same db to store this log table.

should i store it in the same database? keep it in mysql but different database? use sqlite? use redis? i'd love to hear how some of you have this implemented. thanks.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.