| Conditions | 7 |
| Paths | 5 |
| Total Lines | 24 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 3 | Features | 0 |
| 1 | <?php |
||
| 22 | public function isLiked(): bool |
||
| 23 | { |
||
| 24 | $ip = request()->ip(); |
||
| 25 | $userAgent = request()->userAgent(); |
||
| 26 | |||
| 27 | if (auth()->user()) { |
||
| 28 | if ($this->relationLoaded('likes')) { |
||
| 29 | return $this->likes->contains('user_id', auth()->user()->id); |
||
| 30 | } |
||
| 31 | |||
| 32 | return $this->likes()->where('user_id', auth()->user()->id)->exists(); |
||
| 33 | } |
||
| 34 | |||
| 35 | if ($ip && $userAgent) { |
||
| 36 | if ($this->relationLoaded('likes')) { |
||
| 37 | return $this->likes->filter(function ($like) use ($ip, $userAgent) { |
||
| 38 | return $like->ip === $ip && $like->user_agent === $userAgent; |
||
| 39 | })->isNotEmpty(); |
||
| 40 | } |
||
| 41 | |||
| 42 | return $this->likes()->forIp($ip)->forUserAgent($userAgent)->exists(); |
||
| 43 | } |
||
| 44 | |||
| 45 | return false; |
||
| 46 | } |
||
| 66 |