Passed
Push — master ( c5619a...bc0f73 )
by Adam
11:07
created

PostController::subscribe()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Coyote\Http\Controllers\Forum;
4
5
use Coyote\Http\Resources\PostResource;
6
use Coyote\Post;
7
8
class PostController extends BaseController
9
{
10
    /**
11
     * @param \Coyote\Post $post
12
     * @return void
13
     */
14
    public function subscribe($post)
15
    {
16
        $subscriber = $post->subscribers()->forUser($this->userId)->first();
17
18
        if ($subscriber) {
19
            $subscriber->delete();
20
        } else {
21
            $post->subscribers()->create(['user_id' => $this->userId]);
22
        }
23
    }
24
25
    public function show(Post $post)
26
    {
27
        $this->authorize('access', $post->forum);
28
29
        PostResource::withoutWrapping();
30
31
        return new PostResource($post);
32
    }
33
}
34