|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\CommentDeleteRequest; |
|
6
|
|
|
use App\Http\Requests\CommentStoreRequest; |
|
7
|
|
|
use App\Http\Requests\CommentUpdateRequest; |
|
8
|
|
|
use App\Repositories\CommentRepository as Comment; |
|
9
|
|
|
use App\Transformers\CommentTransformer; |
|
10
|
|
|
use Chrisbjr\ApiGuard\Http\Controllers\ApiGuardController; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class CommentController. |
|
14
|
|
|
*/ |
|
15
|
|
|
class CommentController extends ApiGuardController |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var CommentTransformer |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $commentTransformer; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Comment repository. |
|
24
|
|
|
* |
|
25
|
|
|
* @var Comment |
|
26
|
|
|
*/ |
|
27
|
|
|
private $comment; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $apiMethods = [ |
|
33
|
|
|
'getComments' => [ |
|
34
|
|
|
'keyAuthentication' => false, |
|
35
|
|
|
], |
|
36
|
|
|
'store' => [ |
|
37
|
|
|
'limits' => [ |
|
38
|
|
|
'key' => [ |
|
39
|
|
|
'increment' => '1 hour', |
|
40
|
|
|
'limit' => 10, |
|
41
|
|
|
], |
|
42
|
|
|
], |
|
43
|
|
|
], |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* CommentController constructor. |
|
48
|
|
|
* |
|
49
|
|
|
* @param Comment $comment |
|
50
|
|
|
* @param CommentTransformer $commentTransformer |
|
51
|
|
|
*/ |
|
52
|
4 |
|
public function __construct(Comment $comment, CommentTransformer $commentTransformer) |
|
53
|
|
|
{ |
|
54
|
4 |
|
parent::__construct(); |
|
55
|
|
|
|
|
56
|
4 |
|
$this->commentTransformer = $commentTransformer; |
|
57
|
4 |
|
$this->comment = $comment; |
|
58
|
4 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get comments of video. |
|
62
|
|
|
* |
|
63
|
|
|
* @param $video_id |
|
64
|
|
|
* |
|
65
|
|
|
* @return mixed |
|
66
|
|
|
*/ |
|
67
|
4 |
|
public function getComments($video_id) |
|
68
|
|
|
{ |
|
69
|
4 |
|
$comments = $this->comment->getCommentsVideo($video_id); |
|
70
|
|
|
|
|
71
|
4 |
|
return $this->response->withCollection($comments, $this->commentTransformer); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Store comment. |
|
76
|
|
|
* |
|
77
|
|
|
* @param CommentStoreRequest $request |
|
78
|
|
|
* |
|
79
|
|
|
* @return mixed |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function store(CommentStoreRequest $request) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$comment = $this->comment->create($request->all()); |
|
84
|
|
|
|
|
85
|
1 |
|
return $this->response->withItem($comment, $this->commentTransformer); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Update comment. |
|
90
|
|
|
* |
|
91
|
|
|
* @param CommentUpdateRequest $request |
|
92
|
|
|
* @param $id |
|
93
|
|
|
* |
|
94
|
|
|
* @return mixed |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public function update(CommentUpdateRequest $request) |
|
97
|
|
|
{ |
|
98
|
1 |
|
$comment = $this->comment->findOrFail($request->input('id')); |
|
99
|
|
|
|
|
100
|
1 |
|
$this->comment->update($request->all(), $request->input('id')); |
|
101
|
|
|
|
|
102
|
1 |
|
return $this->response->withItem($comment, $this->commentTransformer); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Delete comment. |
|
107
|
|
|
* |
|
108
|
|
|
* @param $id |
|
109
|
|
|
*/ |
|
110
|
2 |
|
public function delete(CommentDeleteRequest $request) |
|
111
|
|
|
{ |
|
112
|
1 |
|
$this->comment->delete($request->input('id')); |
|
113
|
2 |
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: