Files
a.montask/app/Models/Attendance.php
T
2025-07-10 18:23:56 +00:00

47 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Attendance extends Model
{
protected $fillable = [
'user_id',
'user_identity',
'latitude',
'longitude',
'latitude_exit',
'longitude_exit',
'ip_exit',
'latitude_office',
'longitude_office',
'distance',
'ip_address',
'entered_at',
'exited_at',
];
public function setEntryLocationAttribute($value)
{
$this->attributes['entry_location'] = DB::raw("ST_SetSRID(ST_Point({$value['lng']}, {$value['lat']}), 4326)");
}
public function setExitLocationAttribute($value)
{
$this->attributes['exit_location'] = DB::raw("ST_SetSRID(ST_Point({$value['lng']}, {$value['lat']}), 4326)");
}
public function setOfficeLocationAttribute($value)
{
$this->attributes['office_location'] = DB::raw("ST_SetSRID(ST_Point({$value['lng']}, {$value['lat']}), 4326)");
}
public function breaks()
{
return $this->hasMany(AttendanceBreak::class);
}
public $timestamps = true;
}