Selanjutnya buatkan migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('activity_logs', function (Blueprint $table) {
$table->id();
$table->string('action');
$table->string('model');
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->text('message');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('activity_logs');
}
};
Contoh implementasinya pada RoleController method store
public function store(RoleRequest $request)
{
$dataReq = $request->validated();
Role::create($dataReq);
SiteHelpers::activityLog('create', 'Post', auth()->user()->id, 'Created a new role');
return back()->with('success', 'Berhasil Menambahkan Role');
}