first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<?php namespace App\Jobs;
use App\Models\Person;
use App\Models\Title;
use Carbon\Carbon;
class IncrementModelViews
{
public function execute(Person|Title $model): void
{
if (!$this->shouldIncrement($model)) {
return;
}
session()->put(
"{$model->model_type}-views.{$model->model_id}",
Carbon::now()->timestamp,
);
$model->increment('views');
}
private function shouldIncrement(Person|Title $model): bool
{
$views = session("{$model->model_type}-views");
// user has not viewed this model yet
if (!$views || !isset($views[$model->id])) {
return true;
}
// see if user last viewed this model over 10 hours ago
$time = Carbon::createFromTimestamp($views[$model->id]);
return Carbon::now()->diffInHours($time) > 10;
}
}