First commit

This commit is contained in:
Saufi
2026-05-18 08:56:23 +08:00
commit fd3d3a4d2b
147 changed files with 22099 additions and 0 deletions

1
database/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.sqlite*

View File

@@ -0,0 +1,45 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}

View File

@@ -0,0 +1,49 @@
<?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('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};

View File

@@ -0,0 +1,35 @@
<?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('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->bigInteger('expiration')->index();
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->bigInteger('expiration')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};

View File

@@ -0,0 +1,57 @@
<?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('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};

View File

@@ -0,0 +1,44 @@
<?php
// database/migrations/2024_01_01_000001_create_roles_table.php
// Jadual roles untuk RBAC ringkas — admin, staff, viewer
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name')->unique(); // admin, staff, viewer
$table->string('label'); // Admin Sistem, Kakitangan, Pengguna
$table->text('description')->nullable();
$table->timestamps();
});
Schema::create('user_roles', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
$table->timestamps();
$table->unique(['user_id', 'role_id']);
});
// Tambah kolum role pada users untuk single-role semudah mungkin
Schema::table('users', function (Blueprint $table) {
$table->string('role')->default('viewer')->after('password');
// role: admin | staff | viewer
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('role');
});
Schema::dropIfExists('user_roles');
Schema::dropIfExists('roles');
}
};

View File

@@ -0,0 +1,31 @@
<?php
// database/migrations/2024_01_01_000002_create_categories_table.php
// Kategori dokumen — boleh ditambah/diubah/dinyahaktifkan tanpa ubah code
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name'); // Pelesenan, Cukai, dll.
$table->string('slug')->unique(); // pelesenan, cukai, wifi-johor
$table->text('description')->nullable();
$table->string('color', 10)->default('#6c757d'); // warna badge UI
$table->boolean('is_active')->default(true);
$table->integer('sort_order')->default(0);
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('categories');
}
};

View File

@@ -0,0 +1,40 @@
<?php
// database/migrations/2024_01_01_000003_create_documents_table.php
// Metadata dokumen utama — satu rekod per dokumen (bukan per versi)
// Setiap dokumen boleh ada banyak versi dalam document_versions
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('documents', function (Blueprint $table) {
$table->id();
$table->foreignId('category_id')->constrained()->restrictOnDelete();
$table->string('title');
$table->text('description')->nullable();
$table->string('status')->default('draft');
// status: draft | processing | active | inactive | failed
$table->boolean('is_active')->default(false);
$table->date('effective_date')->nullable(); // tarikh kuat kuasa
$table->date('expiry_date')->nullable(); // tarikh luput (optional)
$table->json('tags')->nullable(); // ["lesen", "perniagaan"]
$table->string('language', 10)->default('ms');
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->softDeletes();
$table->index(['category_id', 'is_active']);
$table->index('status');
});
}
public function down(): void
{
Schema::dropIfExists('documents');
}
};

View File

@@ -0,0 +1,44 @@
<?php
// database/migrations/2024_01_01_000004_create_document_versions_table.php
// Setiap upload PDF adalah satu versi baru — versi lama TIDAK dipadam
// Ini adalah source of truth untuk fail asal
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('document_versions', function (Blueprint $table) {
$table->id();
$table->foreignId('document_id')->constrained()->cascadeOnDelete();
$table->unsignedInteger('version_number'); // 1, 2, 3, ...
$table->string('original_filename'); // nama fail asal
$table->string('stored_path'); // path dalam storage
$table->string('mime_type')->default('application/pdf');
$table->unsignedBigInteger('file_size'); // dalam bytes
$table->string('file_hash', 64)->nullable(); // SHA256 untuk detect duplicate
$table->unsignedInteger('page_count')->nullable();
$table->string('processing_status')->default('pending');
// pending | processing | extracting | chunking | embedding | indexed | failed | extraction_failed
$table->text('processing_error')->nullable(); // mesej error jika gagal
$table->timestamp('processing_started_at')->nullable();
$table->timestamp('processing_completed_at')->nullable();
$table->boolean('is_current')->default(false); // hanya satu versi = current
$table->text('change_notes')->nullable(); // nota perubahan versi
$table->foreignId('uploaded_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->unique(['document_id', 'version_number']);
$table->index(['document_id', 'is_current']);
$table->index('processing_status');
});
}
public function down(): void
{
Schema::dropIfExists('document_versions');
}
};

View File

@@ -0,0 +1,40 @@
<?php
// database/migrations/2024_01_01_000005_create_document_chunks_table.php
// Teks yang telah dipecahkan untuk embedding — dikaitkan dengan versi dokumen
// Teks asal disimpan di sini untuk audit, re-embed, dan preview
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('document_chunks', function (Blueprint $table) {
$table->id();
$table->foreignId('document_id')->constrained()->cascadeOnDelete();
$table->foreignId('document_version_id')->constrained()->cascadeOnDelete();
$table->unsignedInteger('chunk_index'); // 0, 1, 2, ...
$table->unsignedInteger('page_number')->nullable(); // muka surat PDF
$table->text('content'); // teks chunk asal
$table->unsignedInteger('token_count')->nullable(); // anggaran token
$table->string('section_heading')->nullable(); // heading jika ada
$table->string('qdrant_point_id', 36)->nullable()->unique();
// UUID simpan di Qdrant — untuk update/delete tepat
$table->boolean('is_embedded')->default(false);
$table->boolean('is_active')->default(true);
$table->timestamp('embedded_at')->nullable();
$table->timestamps();
$table->index(['document_version_id', 'chunk_index']);
$table->index(['document_id', 'is_active']);
$table->index('qdrant_point_id');
});
}
public function down(): void
{
Schema::dropIfExists('document_chunks');
}
};

View File

@@ -0,0 +1,44 @@
<?php
// database/migrations/2024_01_01_000006_create_knowledge_items_table.php
// Knowledge items manual — FAQ, Q&A rasmi, polisi ringkas, nota dalaman
// Ini pelengkap kepada dokumen PDF — admin boleh tambah terus tanpa upload fail
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('knowledge_items', function (Blueprint $table) {
$table->id();
$table->foreignId('category_id')->constrained()->restrictOnDelete();
$table->string('item_type');
// faq | policy | note | announcement
$table->string('title'); // soalan / tajuk polisi
$table->text('content'); // jawapan / kandungan penuh
$table->text('content_short')->nullable(); // ringkasan (optional)
$table->json('tags')->nullable();
$table->string('language', 10)->default('ms');
$table->date('effective_date')->nullable();
$table->date('expiry_date')->nullable();
$table->boolean('is_active')->default(true);
$table->boolean('is_public')->default(true); // boleh dicari oleh public
$table->string('qdrant_point_id', 36)->nullable()->unique();
$table->boolean('is_embedded')->default(false);
$table->timestamp('embedded_at')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->softDeletes();
$table->index(['category_id', 'is_active', 'item_type']);
});
}
public function down(): void
{
Schema::dropIfExists('knowledge_items');
}
};

View File

@@ -0,0 +1,33 @@
<?php
// database/migrations/2024_01_01_000007_create_chat_sessions_table.php
// Sesi perbualan chatbot — satu sesi boleh ada banyak soalan
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('chat_sessions', function (Blueprint $table) {
$table->id();
$table->string('session_token', 64)->unique(); // untuk public user tanpa login
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
// null = soal semua kategori, ada nilai = tapis kategori
$table->string('ip_address', 45)->nullable();
$table->string('user_agent')->nullable();
$table->timestamp('last_activity_at')->nullable();
$table->timestamps();
$table->index(['user_id']);
$table->index('last_activity_at');
});
}
public function down(): void
{
Schema::dropIfExists('chat_sessions');
}
};

View File

@@ -0,0 +1,42 @@
<?php
// database/migrations/2024_01_01_000008_create_chat_logs_table.php
// Log setiap pertanyaan + jawapan AI + sumber yang digunakan
// Ini penting untuk audit, improve FAQ, dan semak kualiti jawapan
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('chat_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('chat_session_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('category_id')->nullable()->constrained()->nullOnDelete();
$table->text('question'); // soalan user
$table->text('answer'); // jawapan AI
$table->json('sources_used')->nullable();
// array of: {type, title, category, page, chunk_id, score}
$table->json('context_chunks')->nullable(); // chunk teks yang dihantar ke model
$table->string('model_used')->nullable(); // nama model Ollama
$table->integer('tokens_used')->nullable(); // anggaran token
$table->float('response_time')->nullable(); // masa (saat)
$table->boolean('has_answer')->default(true); // false = model tidak tahu
$table->boolean('is_flagged')->default(false); // admin flag untuk semak
$table->timestamps();
$table->index(['chat_session_id']);
$table->index(['user_id', 'created_at']);
$table->index('is_flagged');
$table->index('created_at');
});
}
public function down(): void
{
Schema::dropIfExists('chat_logs');
}
};

View File

@@ -0,0 +1,37 @@
<?php
// database/migrations/2024_01_01_000009_create_chat_feedbacks_table.php
// Feedback pengguna untuk setiap jawapan AI
// Admin boleh convert soalan yang gagal dijawab kepada FAQ rasmi
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('chat_feedbacks', function (Blueprint $table) {
$table->id();
$table->foreignId('chat_log_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('rating');
// helpful | not_helpful | partially_helpful
$table->text('comment')->nullable(); // komen pembetulan user
$table->text('correct_answer')->nullable(); // jawapan betul (dari user)
$table->boolean('converted_to_faq')->default(false);
$table->foreignId('converted_faq_id')->nullable()->constrained('knowledge_items')->nullOnDelete();
$table->foreignId('reviewed_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('reviewed_at')->nullable();
$table->timestamps();
$table->index(['chat_log_id']);
$table->index(['rating', 'converted_to_faq']);
});
}
public function down(): void
{
Schema::dropIfExists('chat_feedbacks');
}
};

View File

@@ -0,0 +1,43 @@
<?php
// database/migrations/2024_01_01_000010_create_audit_logs_table.php
// Audit trail sistem — rekod semua tindakan penting oleh admin/sistem
// Tidak boleh diubah atau dipadam — append-only log
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('audit_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('event');
// document.uploaded | document.activated | document.deactivated
// document.reindexed | document.version_added
// knowledge_item.created | knowledge_item.updated | knowledge_item.deactivated
// category.created | category.updated
// faq.converted_from_feedback
// system.reindex_started | system.reindex_completed
$table->string('auditable_type')->nullable(); // model class
$table->unsignedBigInteger('auditable_id')->nullable();
$table->json('old_values')->nullable(); // data sebelum perubahan
$table->json('new_values')->nullable(); // data selepas perubahan
$table->text('description')->nullable(); // huraian tindakan
$table->string('ip_address', 45)->nullable();
$table->string('user_agent')->nullable();
$table->timestamp('created_at'); // hanya created_at (append-only)
$table->index(['user_id', 'created_at']);
$table->index(['auditable_type', 'auditable_id']);
$table->index(['event', 'created_at']);
});
}
public function down(): void
{
Schema::dropIfExists('audit_logs');
}
};

View File

@@ -0,0 +1,35 @@
<?php
// database/migrations/2024_01_01_000011_create_processing_logs_table.php
// Log status pemprosesan setiap document_version — untuk debug dan monitoring
// Berbeza dari audit_logs: ini untuk teknikal, bukan untuk governance
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('processing_logs', function (Blueprint $table) {
$table->id();
$table->string('processable_type'); // DocumentVersion | KnowledgeItem
$table->unsignedBigInteger('processable_id');
$table->string('stage');
// upload | extract | chunk | embed | qdrant_sync | completed | failed
$table->string('status'); // started | completed | failed
$table->text('message')->nullable();
$table->json('metadata')->nullable(); // data tambahan (chunk count, page count, dsb.)
$table->float('duration')->nullable(); // masa dalam saat
$table->timestamp('created_at');
$table->index(['processable_type', 'processable_id']);
$table->index(['stage', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('processing_logs');
}
};

View File

@@ -0,0 +1,118 @@
<?php
// database/migrations/2026_04_08_000001_add_chunk_review_fields_to_document_chunks.php
// Tambah sokongan Chunk Review & Editing:
// - Teks berlapis: cleaned_text, final_text (content kekal sebagai raw_text)
// - Status enum: chunk_status
// - Flags: is_edited, exclude_from_index, needs_reindex
// - Split tracking: parent_chunk_id, split_group_id, split_order
// - Admin metadata: edited_by, edited_at, last_embedded_at, notes
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('document_chunks', function (Blueprint $table) {
// === Teks berlapis ===
// content sedia ada = raw_text (teks asal extraction — TIDAK PERNAH DIUBAH)
$table->longText('cleaned_text')->nullable()->after('content');
// Auto-cleaned text — null bermakna tiada cleanup dilakukan
$table->longText('final_text')->nullable()->after('cleaned_text');
// Teks akhir untuk embedding — null bermakna guna cleaned_text atau content
// === Status chunk ===
// Values: pending, indexed, needs_review, needs_reindex, excluded, superseded, failed_embedding
$table->string('chunk_status', 25)->default('pending')->after('final_text');
// === Admin flags ===
$table->boolean('is_edited')->default(false)->after('is_active');
// true jika admin pernah edit final_text
$table->boolean('exclude_from_index')->default(false)->after('is_edited');
// true jika admin kecualikan chunk dari indexing
$table->boolean('needs_reindex')->default(false)->after('exclude_from_index');
// true jika final_text berubah tapi belum direindex semula
// === Split tracking ===
$table->unsignedBigInteger('parent_chunk_id')->nullable()->after('needs_reindex');
// FK ke chunk asal jika ini adalah hasil split
$table->foreign('parent_chunk_id')
->references('id')
->on('document_chunks')
->nullOnDelete();
$table->string('split_group_id', 36)->nullable()->after('parent_chunk_id');
// UUID bersama untuk semua siblings dalam satu split operation
$table->unsignedTinyInteger('split_order')->nullable()->after('split_group_id');
// 0, 1, 2... untuk susun atur dalam split group
// === Admin editing metadata ===
$table->unsignedBigInteger('edited_by')->nullable()->after('split_order');
$table->foreign('edited_by')
->references('id')
->on('users')
->nullOnDelete();
$table->timestamp('edited_at')->nullable()->after('edited_by');
// Bila admin terakhir kali edit
$table->timestamp('last_embedded_at')->nullable()->after('edited_at');
// Masa embed terkini (berbeza dari embedded_at = masa embed pertama)
$table->text('notes')->nullable()->after('last_embedded_at');
// Nota admin untuk chunk ini
// === Indexes ===
$table->index('chunk_status');
$table->index(['document_version_id', 'chunk_status']);
$table->index('needs_reindex');
$table->index('split_group_id');
});
// Kemaskini chunk_status sedia ada berdasarkan is_embedded dan is_active
DB::statement("
UPDATE document_chunks
SET
chunk_status = CASE
WHEN is_active = 0 THEN 'excluded'
WHEN is_embedded = 1 AND is_active = 1 THEN 'indexed'
ELSE 'pending'
END,
last_embedded_at = embedded_at
");
}
public function down(): void
{
Schema::table('document_chunks', function (Blueprint $table) {
$table->dropForeign(['parent_chunk_id']);
$table->dropForeign(['edited_by']);
$table->dropIndex(['chunk_status']);
$table->dropIndex(['document_version_id', 'chunk_status']);
$table->dropIndex(['needs_reindex']);
$table->dropIndex(['split_group_id']);
$table->dropColumn([
'cleaned_text',
'final_text',
'chunk_status',
'is_edited',
'exclude_from_index',
'needs_reindex',
'parent_chunk_id',
'split_group_id',
'split_order',
'edited_by',
'edited_at',
'last_embedded_at',
'notes',
]);
});
}
};

View File

@@ -0,0 +1,63 @@
<?php
// database/migrations/2026_04_08_000002_create_chunk_audits_table.php
// Audit trail khusus untuk operasi chunk:
// edit_final_text, exclude, include, reindex, split_parent, split_child
//
// Berbeza dari audit_logs: chunk_audits simpan perubahan teks sebenar (old/new final_text)
// yang terlalu besar untuk disimpan dalam kolum JSON audit_logs.
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('chunk_audits', function (Blueprint $table) {
$table->id();
$table->foreignId('document_chunk_id')
->constrained('document_chunks')
->cascadeOnDelete();
$table->foreignId('user_id')
->nullable()
->constrained('users')
->nullOnDelete();
$table->string('operation', 30);
// 'edit_final_text' | 'exclude' | 'include' | 'reindex'
// | 'split_parent' | 'split_child'
// Perubahan teks (boleh null jika operasi bukan edit teks)
$table->longText('old_final_text')->nullable();
$table->longText('new_final_text')->nullable();
// Perubahan status
$table->string('old_status', 25)->nullable();
$table->string('new_status', 25)->nullable();
// Metadata tambahan (parent_chunk_id, split_group_id, bilangan segmen, dll.)
$table->json('metadata')->nullable();
$table->text('notes')->nullable();
// Nota admin yang dimasukkan semasa operasi
$table->string('ip_address', 45)->nullable();
// Append-only — hanya created_at, tiada updated_at
$table->timestamp('created_at')->useCurrent();
$table->index(['document_chunk_id', 'created_at']);
$table->index('operation');
$table->index('user_id');
});
}
public function down(): void
{
Schema::dropIfExists('chunk_audits');
}
};

View File

@@ -0,0 +1,78 @@
<?php
namespace Database\Seeders;
use App\Models\Category;
use Illuminate\Database\Seeder;
class CategorySeeder extends Seeder
{
/**
* Kategori awal mengikut keperluan sistem.
* Kategori boleh ditambah, diubah, atau dinyahaktifkan
* melalui admin panel tanpa perlu ubah code.
*/
public function run(): void
{
$categories = [
[
'name' => 'Pelesenan',
'slug' => 'pelesenan',
'description' => 'Maklumat berkaitan lesen perniagaan, lesen premis, dan kelulusan berkaitan.',
'color' => '#3b82f6', // biru
'sort_order' => 1,
],
[
'name' => 'Cukai',
'slug' => 'cukai',
'description' => 'Maklumat berkaitan cukai taksiran, cukai pintu, dan bayaran berkaitan harta.',
'color' => '#10b981', // hijau
'sort_order' => 2,
],
[
'name' => 'WiFi Johor',
'slug' => 'wifi-johor',
'description' => 'Maklumat dan panduan penggunaan WiFi Johor di kawasan awam.',
'color' => '#6366f1', // ungu
'sort_order' => 3,
],
[
'name' => 'Permohonan Permit Sementara',
'slug' => 'permohonan-permit-sementara',
'description' => 'Maklumat berkaitan permit sementara untuk aktiviti, acara, atau pembinaan.',
'color' => '#f59e0b', // kuning
'sort_order' => 4,
],
[
'name' => 'Penguatkuasaan',
'slug' => 'penguatkuasaan',
'description' => 'Maklumat berkaitan tindakan penguatkuasaan, kompaun, dan prosedur aduan.',
'color' => '#ef4444', // merah
'sort_order' => 5,
],
[
'name' => 'Sewaan Gerai Majlis',
'slug' => 'sewaan-gerai-majlis',
'description' => 'Maklumat berkaitan sewaan gerai, premis, dan kemudahan majlis.',
'color' => '#14b8a6', // teal
'sort_order' => 6,
],
[
'name' => 'Lain-lain',
'slug' => 'lain-lain',
'description' => 'Soalan umum dan maklumat yang tidak termasuk dalam kategori khusus.',
'color' => '#6b7280', // kelabu
'sort_order' => 99,
],
];
foreach ($categories as $data) {
Category::updateOrCreate(
['slug' => $data['slug']],
array_merge($data, ['is_active' => true])
);
}
$this->command->info('✓ ' . count($categories) . ' kategori berjaya dibuat/dikemaskini.');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$this->call([
UserSeeder::class,
CategorySeeder::class,
KnowledgeItemSeeder::class,
]);
}
}

View File

@@ -0,0 +1,156 @@
<?php
namespace Database\Seeders;
use App\Models\Category;
use App\Models\KnowledgeItem;
use Illuminate\Database\Seeder;
class KnowledgeItemSeeder extends Seeder
{
/**
* Sample FAQ untuk development dan demo awal.
* Data ini bukan fakta sebenar untuk tujuan ujian sahaja.
*/
public function run(): void
{
$items = [
// ── Pelesenan ─────────────────────────────────────────────────
[
'category_slug' => 'pelesenan',
'item_type' => KnowledgeItem::TYPE_FAQ,
'title' => 'Apakah dokumen yang diperlukan untuk memohon lesen perniagaan baru?',
'content' => "Untuk memohon lesen perniagaan baru, pemohon perlu menyediakan dokumen berikut:\n\n" .
"1. Salinan kad pengenalan pemohon (MyKad)\n" .
"2. Borang permohonan yang telah dilengkapkan\n" .
"3. Salinan geran tanah atau perjanjian sewaan premis\n" .
"4. Pelan lantai premis perniagaan\n" .
"5. Sijil pendaftaran perniagaan (SSM)\n" .
"6. Gambar premis dari dalam dan luar\n\n" .
"Sila hubungi Bahagian Pelesenan untuk maklumat lanjut.",
'tags' => ['lesen', 'perniagaan', 'permohonan', 'dokumen'],
'is_active' => true,
],
[
'category_slug' => 'pelesenan',
'item_type' => KnowledgeItem::TYPE_FAQ,
'title' => 'Berapa lama masa yang diperlukan untuk kelulusan lesen perniagaan?',
'content' => "Proses kelulusan lesen perniagaan biasanya mengambil masa 14 hingga 30 hari bekerja " .
"bergantung kepada jenis lesen dan kelengkapan dokumen yang dikemukakan.\n\n" .
"Pemohon boleh semak status permohonan melalui kaunter Bahagian Pelesenan atau " .
"menghubungi talian hotline kami.",
'tags' => ['lesen', 'tempoh', 'kelulusan'],
'is_active' => true,
],
// ── Cukai ─────────────────────────────────────────────────────
[
'category_slug' => 'cukai',
'item_type' => KnowledgeItem::TYPE_FAQ,
'title' => 'Bila tarikh akhir pembayaran cukai taksiran?',
'content' => "Cukai taksiran perlu dibayar dalam dua penggal:\n\n" .
"• Penggal pertama: 28 Februari setiap tahun\n" .
"• Penggal kedua: 31 Ogos setiap tahun\n\n" .
"Bayaran lewat akan dikenakan denda atau caj penalti. " .
"Pembayaran boleh dibuat di kaunter, atas talian, atau melalui bank.",
'tags' => ['cukai', 'taksiran', 'tarikh', 'bayaran'],
'is_active' => true,
],
// ── WiFi Johor ────────────────────────────────────────────────
[
'category_slug' => 'wifi-johor',
'item_type' => KnowledgeItem::TYPE_FAQ,
'title' => 'Bagaimana cara untuk sambung ke WiFi Johor?',
'content' => "Cara menyambung ke WiFi Johor:\n\n" .
"1. Hidupkan WiFi pada peranti anda\n" .
"2. Pilih rangkaian 'WiFi Johor' atau 'WiFiJohor'\n" .
"3. Buka pelayar web — halaman log masuk akan muncul\n" .
"4. Daftar menggunakan nombor telefon atau e-mel\n" .
"5. Masukkan OTP yang diterima\n" .
"6. Anda kini boleh menggunakan internet percuma\n\n" .
"WiFi Johor tersedia di taman awam, perpustakaan, dan bangunan kerajaan terpilih.",
'tags' => ['wifi', 'johor', 'internet', 'sambung'],
'is_active' => true,
],
// ── Penguatkuasaan ────────────────────────────────────────────
[
'category_slug' => 'penguatkuasaan',
'item_type' => KnowledgeItem::TYPE_FAQ,
'title' => 'Bagaimana cara untuk membuat aduan berkaitan penguatkuasaan?',
'content' => "Aduan berkaitan penguatkuasaan boleh dibuat melalui cara berikut:\n\n" .
"1. Kaunter aduan di Jabatan Penguatkuasaan\n" .
"2. Hotline: 07-XXX XXXX (Isnin-Jumaat, 8pagi-5ptg)\n" .
"3. E-mel: penguatkuasaan@majlis.gov.my\n" .
"4. Sistem aduan atas talian\n\n" .
"Sertakan maklumat berikut dalam aduan:\n" .
"• Nama dan nombor telefon pengadu\n" .
"• Lokasi kejadian\n" .
"• Tarikh dan masa kejadian\n" .
"• Penerangan ringkas masalah",
'tags' => ['aduan', 'penguatkuasaan', 'prosedur'],
'is_active' => true,
],
// ── Sewaan Gerai ──────────────────────────────────────────────
[
'category_slug' => 'sewaan-gerai-majlis',
'item_type' => KnowledgeItem::TYPE_FAQ,
'title' => 'Apakah syarat untuk menyewa gerai majlis?',
'content' => "Syarat-syarat untuk menyewa gerai majlis:\n\n" .
"1. Pemohon mestilah warganegara Malaysia\n" .
"2. Berumur 18 tahun ke atas\n" .
"3. Tiada tunggakan dengan pihak majlis\n" .
"4. Mempunyai lesen perniagaan yang sah (jika berniaga)\n" .
"5. Menandatangani perjanjian sewaan\n\n" .
"Kadar sewa bergantung kepada lokasi dan jenis gerai. " .
"Sila rujuk jadual kadar sewa yang terkini di kaunter.",
'tags' => ['gerai', 'sewa', 'syarat', 'permohonan'],
'is_active' => true,
],
// ── Lain-lain ─────────────────────────────────────────────────
[
'category_slug' => 'lain-lain',
'item_type' => KnowledgeItem::TYPE_FAQ,
'title' => 'Apakah waktu operasi pejabat majlis?',
'content' => "Waktu operasi pejabat majlis adalah seperti berikut:\n\n" .
"• Isnin Khamis: 8:00 pagi 5:00 petang\n" .
"• Jumaat: 8:00 pagi 12:00 tengah hari (tutup 12:15 2:45 ptg)\n" .
"• Sabtu, Ahad, dan Cuti Umum: Tutup\n\n" .
"Perkhidmatan kaunter ditutup 15 minit sebelum masa tutup pejabat.",
'tags' => ['waktu', 'operasi', 'pejabat', 'jadual'],
'is_active' => true,
],
];
$count = 0;
foreach ($items as $data) {
$slug = $data['category_slug'];
unset($data['category_slug']);
$category = Category::where('slug', $slug)->first();
if (!$category) {
$this->command->warn(" Kategori '{$slug}' tidak dijumpai. Skip.");
continue;
}
KnowledgeItem::updateOrCreate(
[
'category_id' => $category->id,
'title' => $data['title'],
],
array_merge($data, [
'category_id' => $category->id,
'language' => 'ms',
'is_public' => true,
])
);
$count++;
}
$this->command->info("{$count} knowledge items (sample FAQ) berjaya dibuat.");
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
class UserSeeder extends Seeder
{
/**
* Buat pengguna awal untuk development.
* JANGAN guna kata laluan ini dalam production.
*/
public function run(): void
{
// Admin
User::updateOrCreate(
['email' => 'admin@example.com'],
[
'name' => 'Admin Sistem',
'password' => Hash::make('password'),
'role' => User::ROLE_ADMIN,
]
);
// Staff
User::updateOrCreate(
['email' => 'staff@example.com'],
[
'name' => 'Kakitangan',
'password' => Hash::make('password'),
'role' => User::ROLE_STAFF,
]
);
$this->command->info('✓ 2 pengguna awal berjaya dibuat.');
$this->command->warn(' Admin: admin@example.com / password');
$this->command->warn(' Staff: staff@example.com / password');
$this->command->warn(' TUKAR KATA LALUAN SEBELUM DEPLOY KE PRODUCTION!');
}
}