51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Carbon\Carbon;
|
|
|
|
class PerizinanStatus extends Model
|
|
{
|
|
protected $table = 'perizinan_status';
|
|
|
|
protected $fillable = [
|
|
'kategori',
|
|
'status_id',
|
|
'label',
|
|
'value',
|
|
'api_last_updated',
|
|
'sync_date'
|
|
];
|
|
|
|
protected $casts = [
|
|
'api_last_updated' => 'datetime',
|
|
'sync_date' => 'date',
|
|
'value' => 'integer'
|
|
];
|
|
|
|
/**
|
|
* Get latest data by kategori
|
|
*/
|
|
public static function getLatestByKategori($kategori)
|
|
{
|
|
return self::where('kategori', $kategori)
|
|
->whereDate('sync_date', Carbon::today())
|
|
->get()
|
|
->keyBy('status_id');
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
->get()
|
|
->keyBy('status_id');
|
|
}
|
|
}
|