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/be.naniguide.com/app/Model/FunnelConversion.php
<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use App\Library\Traits\HasUid;

class FunnelConversion extends Model
{
    use HasUid;

    public const TYPE_OPTIN = 'optin';
    public const TYPE_ADD_TO_CART = 'add_to_cart';
    public const TYPE_CHECKOUT_STARTED = 'checkout_started';
    public const TYPE_PURCHASE = 'purchase';

    protected $casts = [
        'metadata'     => 'array',
        'value'        => 'decimal:2',
        'converted_at' => 'datetime',
    ];

    public function funnel()
    {
        return $this->belongsTo(Funnel::class);
    }

    public function step()
    {
        return $this->belongsTo(FunnelStep::class, 'funnel_step_id');
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function scopeOfCustomer($query, $customer)
    {
        return $query->where('customer_id', $customer->id);
    }

    public function scopeOfFunnel($query, $funnel)
    {
        return $query->where('funnel_id', $funnel->id);
    }

    public function scopeOfType($query, $type)
    {
        return $query->where('type', $type);
    }

    public function scopeDateRange($query, $from, $to)
    {
        if ($from) $query->where('converted_at', '>=', $from);
        if ($to) $query->where('converted_at', '<=', $to);
    }
}