57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class ApiLog extends Model
|
|
{
|
|
protected $fillable = [
|
|
'job_source_id',
|
|
'endpoint',
|
|
'method',
|
|
'status_code',
|
|
'response_time_ms',
|
|
'success',
|
|
'error_message',
|
|
'request_params',
|
|
'response_data',
|
|
];
|
|
|
|
protected $casts = [
|
|
'success' => 'boolean',
|
|
'request_params' => 'array',
|
|
'response_data' => 'array',
|
|
];
|
|
|
|
public function source(): BelongsTo
|
|
{
|
|
return $this->belongsTo(JobSource::class, 'job_source_id');
|
|
}
|
|
|
|
/**
|
|
* Scope to get only successful logs
|
|
*/
|
|
public function scopeSuccessful($query)
|
|
{
|
|
return $query->where('success', true);
|
|
}
|
|
|
|
/**
|
|
* Scope to get only failed logs
|
|
*/
|
|
public function scopeFailed($query)
|
|
{
|
|
return $query->where('success', false);
|
|
}
|
|
|
|
/**
|
|
* Scope to get logs within a date range
|
|
*/
|
|
public function scopeWithinDays($query, int $days)
|
|
{
|
|
return $query->where('created_at', '>=', now()->subDays($days));
|
|
}
|
|
}
|