Passed
Push — dependabot/npm_and_yarn/dev/st... ( 917c39...79f3f4 )
by
unknown
12:32 queued 07:14
created

CommentApiController::indexByJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
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\Request;
10
use Illuminate\Http\Resources\Json\JsonResource;
11
use Illuminate\Http\Resources\Json\ResourceCollection;
12
use Illuminate\Support\Facades\Log;
13
14
class CommentApiController extends Controller
15
{
16
    /**
17
     * Get the set of comments associated with a Job.
18
     *
19
     * @param JobPoster $jobPoster
20
     * @return \Illuminate\Http\Response
21
     */
22
    public function indexByJob(JobPoster $jobPoster)
23
    {
24
          $comments = Comment::where('job_poster_id', $jobPoster->id)->get();
25
          return response()->json(new ResourceCollection($comments));
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
          return /** @scrutinizer ignore-call */ response()->json(new ResourceCollection($comments));
Loading history...
26
    }
27
28
    /**
29
     * Store a newly created resource in storage
30
     *
31
     * @param \App\Http\Requests\StoreComment $request Incoming request.
32
     * @param  \App\Models\JobPoster          $jobPoster    Incoming Job Poster.
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function store(StoreComment $request, JobPoster $jobPoster)
36
    {
37
          $data = $request->validated();
38
          $comment = new Comment();
39
          $comment->user_id = $request->user()->id;
40
          $comment->job_poster_id = $jobPoster->id;
41
          $comment->fill($data);
42
          $comment->save();
43
          return response()->json(new JsonResource($comment));
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
          return /** @scrutinizer ignore-call */ response()->json(new JsonResource($comment));
Loading history...
44
    }
45
}
46