Total Complexity | 7 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
11 | class Like extends Component |
||
12 | { |
||
13 | |||
14 | public $comment; |
||
15 | public $count; |
||
16 | |||
17 | |||
18 | public function mount(\Usamamuneerchaudhary\Commentify\Models\Comment $comment): void |
||
22 | } |
||
23 | |||
24 | public function like(): void |
||
25 | { |
||
26 | $ip = request()->ip(); |
||
27 | $userAgent = request()->userAgent(); |
||
28 | if ($this->comment->isLiked()) { |
||
29 | $this->comment->removeLike(); |
||
30 | |||
31 | $this->count--; |
||
32 | } elseif (auth()->user()) { |
||
33 | $this->comment->likes()->create([ |
||
34 | 'user_id' => auth()->id(), |
||
35 | ]); |
||
36 | |||
37 | $this->count++; |
||
38 | } elseif ($ip && $userAgent) { |
||
39 | $this->comment->likes()->create([ |
||
40 | 'ip' => $ip, |
||
41 | 'user_agent' => $userAgent, |
||
42 | ]); |
||
43 | |||
44 | $this->count++; |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @return Factory|Application|View|\Illuminate\Contracts\Foundation\Application|null |
||
50 | */ |
||
51 | public function render( |
||
55 | } |
||
56 | |||
58 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.