75 lines
1.4 KiB
PHP
75 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Attendance extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'user_id',
|
|
'date',
|
|
'check_in',
|
|
'check_out',
|
|
'status',
|
|
'lates_minutes',
|
|
'notes',
|
|
'device_info',
|
|
'location',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'date' => 'date',
|
|
'check_in' => 'datetime',
|
|
'check_out' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the user that owns the attendance.
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get pengajuans linked to this attendance.
|
|
*/
|
|
public function pengajuan()
|
|
{
|
|
return $this->hasOne(Pengajuan::class, 'id_attendance');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include today's attendance.
|
|
*/
|
|
public function scopeToday($query)
|
|
{
|
|
return $query->whereDate('date', today());
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include attendance for a specific date.
|
|
*/
|
|
public function scopeForDate($query, $date)
|
|
{
|
|
return $query->whereDate('date', $date);
|
|
}
|
|
}
|