55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Carbon\Carbon;
|
|
|
|
class FastestPermohonan extends Model
|
|
{
|
|
protected $table = 'fastest_permohonan';
|
|
|
|
protected $fillable = [
|
|
'kategori',
|
|
'nama',
|
|
'total',
|
|
'durasi_pemohon',
|
|
'durasi_petugas',
|
|
'api_last_updated',
|
|
'sync_date'
|
|
];
|
|
|
|
protected $casts = [
|
|
'api_last_updated' => 'datetime',
|
|
'sync_date' => 'date',
|
|
'total' => 'integer'
|
|
];
|
|
|
|
/**
|
|
* Get fastest permohonan by kategori for today, ordered by API response order
|
|
* Since API already provides fastest data in correct order
|
|
*/
|
|
public static function getLatestByKategori($kategori)
|
|
{
|
|
return self::where('kategori', $kategori)
|
|
->whereDate('sync_date', Carbon::today())
|
|
->orderBy('id') // Keep API order by using insertion order
|
|
->limit(5)
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* Get data for specific kategori and date
|
|
*/
|
|
public static function getByKategoriAndDate($kategori, $date = null)
|
|
{
|
|
$date = $date ?: Carbon::today();
|
|
|
|
return self::where('kategori', $kategori)
|
|
->whereDate('sync_date', $date)
|
|
->orderBy('id') // Keep API order by using insertion order
|
|
->limit(5)
|
|
->get();
|
|
}
|
|
}
|