• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visavi / rotor / 29162167066

11 Jul 2026 05:44PM UTC coverage: 32.95%. Remained the same
29162167066

push

github

visavi
Увеличение счетчика скачивания и просмотров больше не тригерит observer

0 of 1 new or added line in 1 file covered. (0.0%)

1864 of 5657 relevant lines covered (32.95%)

3.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/Models/Reader.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Models;
6

7
use Carbon\CarbonImmutable;
8
use Illuminate\Database\Eloquent\Model;
9
use Illuminate\Database\Eloquent\Relations\BelongsTo;
10

11
/**
12
 * Class Reader
13
 *
14
 * @property int             $id
15
 * @property string          $relate_type
16
 * @property int             $relate_id
17
 * @property string          $ip
18
 * @property CarbonImmutable $created_at
19
 */
20
class Reader extends Model
21
{
22
    /**
23
     * The name of the "updated at" column.
24
     */
25
    public const ?string UPDATED_AT = null;
26

27
    /**
28
     * The attributes that aren't mass assignable.
29
     */
30
    protected $guarded = [];
31

32
    /**
33
     * Get the attributes that should be cast.
34
     */
35
    protected function casts(): array
×
36
    {
37
        return [
×
38
            'user_id' => 'int',
×
39
        ];
×
40
    }
41

42
    /**
43
     * Возвращает связь пользователя
44
     */
45
    public function user(): BelongsTo
×
46
    {
47
        return $this->belongsTo(User::class, 'user_id')->withDefault();
×
48
    }
49

50
    /**
51
     * Counting stat
52
     *
53
     * @param Model&object{countingField: string} $model
54
     */
55
    public static function countingStat(Model $model): void
×
56
    {
57
        $reader = self::query()
×
58
            ->where('relate_type', $model->getMorphClass())
×
59
            ->where('relate_id', $model->getKey())
×
60
            ->where('ip', getIp())
×
61
            ->first();
×
62

63
        if (! $reader) {
×
64
            self::query()->create([
×
65
                'relate_type' => $model->getMorphClass(),
×
66
                'relate_id'   => $model->getKey(),
×
67
                'ip'          => getIp(),
×
68
            ]);
×
69

70
            // Счётчик просмотров/скачиваний — не изменение контента, observers не дёргаем
NEW
71
            $model->incrementQuietly($model->countingField);
×
72
        }
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc