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