HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
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;
    }
}