41 lines
796 B
PHP
41 lines
796 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class AnalyticsProductVisit extends Model
|
|
{
|
|
protected $connection = 'ecommerce';
|
|
protected $table = 'analytics_product_visits';
|
|
|
|
|
|
protected $fillable = [
|
|
'item_id',
|
|
'user_id',
|
|
'session_id',
|
|
'started_at',
|
|
'ended_at',
|
|
'duration_seconds',
|
|
'ip_address',
|
|
'device_type',
|
|
'user_agent',
|
|
'referrer',
|
|
];
|
|
|
|
protected $casts = [
|
|
'started_at' => 'datetime',
|
|
'ended_at' => 'datetime',
|
|
];
|
|
|
|
|
|
public function calculateDuration(): void
|
|
{
|
|
if ($this->started_at && $this->ended_at) {
|
|
$this->duration_seconds =
|
|
$this->ended_at->diffInSeconds($this->started_at);
|
|
}
|
|
}
|
|
|
|
}
|