1 | <?php |
||
2 | |||
3 | namespace RecentlyViewed\Models\Traits; |
||
4 | |||
5 | use Illuminate\Database\Eloquent\Builder; |
||
6 | |||
7 | /** |
||
8 | * Trait CanBeViewed |
||
9 | * @package RecentlyViewed\Models\Traits |
||
10 | * |
||
11 | */ |
||
12 | trait CanBeViewed |
||
13 | { |
||
14 | /** |
||
15 | * @param array $values |
||
16 | * |
||
17 | * @return null|Builder |
||
18 | */ |
||
19 | 1 | public function whereRecentlyViewedIn(array $values): ?Builder |
|
20 | { |
||
21 | 1 | $values = array_filter($values, fn ($v) => (is_int($v) || is_string($v))); |
|
22 | |||
23 | 1 | if (count($values)) { |
|
24 | 1 | return static::whereIn($this->getKeyName(), $values); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
25 | } |
||
26 | |||
27 | 1 | return null; |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * Get recently viewed items count. |
||
32 | * |
||
33 | * @return int |
||
34 | */ |
||
35 | 9 | public function getRecentlyViewsLimit(): int |
|
36 | { |
||
37 | 9 | return (int) (property_exists($this, 'recentlyViewsLimit') ? $this->recentlyViewsLimit : 10); |
|
38 | } |
||
39 | } |
||
40 |