File: /home/xedaptot/ai.naniguide.com/app/Model/FunnelPageView.php
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class FunnelPageView extends Model
{
protected $guarded = [];
protected $casts = [
'viewed_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 scopeDateRange($query, $from, $to)
{
if ($from) $query->where('viewed_at', '>=', $from);
if ($to) $query->where('viewed_at', '<=', $to);
}
}