Passed
Push — task/comments-api ( 6d7a22 )
by Yonathan
13:12
created

CommentController::indexByJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\StoreComment;
7
use App\Models\Comment;
8
use App\Models\JobPoster;
9
use Illuminate\Http\Resources\Json\JsonResource;
10
use Illuminate\Http\Resources\Json\ResourceCollection;
11
use Illuminate\Support\Facades\Log;
12
13
class CommentController extends Controller
14
{
15
    /**
16
     * Get the set of comments associated with a Job.
17
     *
18
     * @param JobPoster $jobPoster
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
19
     * @return \Illuminate\Http\Response
20
     */
21
    public function indexByJob(JobPoster $jobPoster)
22
    {
23
      Log::debug($jobPoster->id);
24
          $comments = Comment::where('job_poster_id', $jobPoster->id)->get();
25
          return new ResourceCollection($comments);
26
    }
27
28
    /**
29
     * Store a newly created resource in storage
30
     *
31
     * @param \App\Http\Requests\StoreComment $request Incoming request.
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function store(StoreComment $request)
35
    {
36
          $data = $request->validated();
37
          $comment = new Comment();
38
          $comment->fill($data);
39
          $comment->save();
40
          return new JsonResource($comment);
41
    }
42
}
43