File: /home/xedaptot/ai.naniguide.com/app/Model/AdMetric.php
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class AdMetric extends Model
{
protected $table = 'ad_metrics';
protected $fillable = [
'ad_campaign_id',
'platform',
'date',
'impressions',
'clicks',
'spend',
'conversions',
'ctr',
'cpc',
'cpm',
'roas',
'custom',
];
protected $casts = [
'date' => 'date',
'impressions' => 'integer',
'clicks' => 'integer',
'spend' => 'decimal:2',
'conversions' => 'integer',
'ctr' => 'decimal:4',
'cpc' => 'decimal:2',
'cpm' => 'decimal:2',
'roas' => 'decimal:2',
'custom' => 'json',
];
public function campaign()
{
return $this->belongsTo(AdCampaign::class, 'ad_campaign_id');
}
public function scopeOfCampaign($query, $campaignId)
{
return $query->where('ad_campaign_id', $campaignId);
}
public function scopeDateRange($query, $start, $end)
{
if ($start) {
$query->where('date', '>=', $start);
}
if ($end) {
$query->where('date', '<=', $end);
}
return $query;
}
}