Files
aplikasi-ketertiban/database/migrations/2026_07_22_161010_create_attendances_table.php
Bro 31ef9c0b0b system-locked violation types (alpha & terlambat) + proporsional poin alpha per jam
- Migration: add is_system column to violation_types, mark alpha & terlambat
- DestroyType guard: system types cannot be deleted
- UpdateType guard: slug tetap walau nama diubah untuk system types
- UI: delete button hidden, badge lock untuk system types
- Seeder: ViolationTypeDefaultsSeeder untuk fresh deploy
- AttendanceController: lookup by slug (alpha/terlambat) instead of fuzzy match
- Alpha auto-violation: poin proporsional per jam (round((points/10)*count), min 1)
- Terlambat auto-violation: poin fix sesuai jenis (2 poin)
- Also handles both A (alpha) and T (terlambat) statuses for auto-violations
2026-07-22 23:55:27 +07:00

32 lines
1.0 KiB
PHP

<?php
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('attendances', function (Blueprint $table) {
$table->id();
$table->foreignId('student_id')->constrained()->cascadeOnDelete();
$table->date('date');
$table->unsignedTinyInteger('lesson_hour')->comment('Jam ke- 1 s.d 10');
$table->string('status', 20)->default('hadir')->comment('hadir|sakit|izin|alpha|terlambat');
$table->text('notes')->nullable();
$table->foreignId('recorded_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->unique(['student_id', 'date', 'lesson_hour'], 'attendance_unique');
$table->index('date');
$table->index('status');
});
}
public function down(): void
{
Schema::dropIfExists('attendances');
}
};