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);
}
}