Employee & Attendance
An employee attendance tracking system with daily check-in/check-out records, work hours calculation, and shift management.
ERD Concept
One-to-Many: Employees have many attendance records. Each record tracks check-in and check-out times for calculating work hours.
Tables
employees
id
user_id (FK)
employee_number
department
position
hire_date
timestamps
attendances
id
employee_id (FK)
date
check_in
check_out
hours_worked
status
notes
timestamps
leaves
id
employee_id (FK)
type
start_date
end_date
reason
status
approved_by (FK)
timestamps
Relationships
- Employee belongsTo User
- Employee hasMany Attendance
- Employee hasMany Leave
Migration
Migration
Schema::create('employees', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('employee_number')->unique();
$table->string('department');
$table->string('position');
$table->date('hire_date');
$table->timestamps();
});
Schema::create('attendances', function (Blueprint $table) {
$table->id();
$table->foreignId('employee_id')->constrained()->cascadeOnDelete();
$table->date('date');
$table->time('check_in')->nullable();
$table->time('check_out')->nullable();
$table->decimal('hours_worked', 4, 2)->default(0);
$table->enum('status', ['present', 'absent', 'late', 'half_day'])->default('present');
$table->text('notes')->nullable();
$table->timestamps();
$table->unique(['employee_id', 'date']);
});
Schema::create('leaves', function (Blueprint $table) {
$table->id();
$table->foreignId('employee_id')->constrained()->cascadeOnDelete();
$table->enum('type', ['sick', 'vacation', 'personal', 'maternity']);
$table->date('start_date');
$table->date('end_date');
$table->text('reason');
$table->enum('status', ['pending', 'approved', 'rejected'])->default('pending');
$table->foreignId('approved_by')->nullable()->constrained('employees');
$table->timestamps();
});