@@ -85,9 +85,9 @@ trait ResponseTrait
85
85
*
86
86
* @param array|string|null $data
87
87
*
88
- * @return mixed
88
+ * @return Response
89
89
*/
90
- public function respond ($ data = null , ?int $ status = null , string $ message = '' )
90
+ protected function respond ($ data = null , ?int $ status = null , string $ message = '' )
91
91
{
92
92
if ($ data === null && $ status === null ) {
93
93
$ status = 404 ;
@@ -119,9 +119,9 @@ public function respond($data = null, ?int $status = null, string $message = '')
119
119
* @param int $status HTTP status code
120
120
* @param string|null $code Custom, API-specific, error code
121
121
*
122
- * @return mixed
122
+ * @return Response
123
123
*/
124
- public function fail ($ messages , int $ status = 400 , ?string $ code = null , string $ customMessage = '' )
124
+ protected function fail ($ messages , int $ status = 400 , ?string $ code = null , string $ customMessage = '' )
125
125
{
126
126
if (! is_array ($ messages )) {
127
127
$ messages = ['error ' => $ messages ];
@@ -145,9 +145,9 @@ public function fail($messages, int $status = 400, ?string $code = null, string
145
145
*
146
146
* @param mixed $data
147
147
*
148
- * @return mixed
148
+ * @return Response
149
149
*/
150
- public function respondCreated ($ data = null , string $ message = '' )
150
+ protected function respondCreated ($ data = null , string $ message = '' )
151
151
{
152
152
return $ this ->respond ($ data , $ this ->codes ['created ' ], $ message );
153
153
}
@@ -157,9 +157,9 @@ public function respondCreated($data = null, string $message = '')
157
157
*
158
158
* @param mixed $data
159
159
*
160
- * @return mixed
160
+ * @return Response
161
161
*/
162
- public function respondDeleted ($ data = null , string $ message = '' )
162
+ protected function respondDeleted ($ data = null , string $ message = '' )
163
163
{
164
164
return $ this ->respond ($ data , $ this ->codes ['deleted ' ], $ message );
165
165
}
@@ -169,9 +169,9 @@ public function respondDeleted($data = null, string $message = '')
169
169
*
170
170
* @param mixed $data
171
171
*
172
- * @return mixed
172
+ * @return Response
173
173
*/
174
- public function respondUpdated ($ data = null , string $ message = '' )
174
+ protected function respondUpdated ($ data = null , string $ message = '' )
175
175
{
176
176
return $ this ->respond ($ data , $ this ->codes ['updated ' ], $ message );
177
177
}
@@ -180,9 +180,9 @@ public function respondUpdated($data = null, string $message = '')
180
180
* Used after a command has been successfully executed but there is no
181
181
* meaningful reply to send back to the client.
182
182
*
183
- * @return mixed
183
+ * @return Response
184
184
*/
185
- public function respondNoContent (string $ message = 'No Content ' )
185
+ protected function respondNoContent (string $ message = 'No Content ' )
186
186
{
187
187
return $ this ->respond (null , $ this ->codes ['no_content ' ], $ message );
188
188
}
@@ -192,9 +192,9 @@ public function respondNoContent(string $message = 'No Content')
192
192
* or had bad authorization credentials. User is encouraged to try again
193
193
* with the proper information.
194
194
*
195
- * @return mixed
195
+ * @return Response
196
196
*/
197
- public function failUnauthorized (string $ description = 'Unauthorized ' , ?string $ code = null , string $ message = '' )
197
+ protected function failUnauthorized (string $ description = 'Unauthorized ' , ?string $ code = null , string $ message = '' )
198
198
{
199
199
return $ this ->fail ($ description , $ this ->codes ['unauthorized ' ], $ code , $ message );
200
200
}
@@ -203,31 +203,31 @@ public function failUnauthorized(string $description = 'Unauthorized', ?string $
203
203
* Used when access is always denied to this resource and no amount
204
204
* of trying again will help.
205
205
*
206
- * @return mixed
206
+ * @return Response
207
207
*/
208
- public function failForbidden (string $ description = 'Forbidden ' , ?string $ code = null , string $ message = '' )
208
+ protected function failForbidden (string $ description = 'Forbidden ' , ?string $ code = null , string $ message = '' )
209
209
{
210
210
return $ this ->fail ($ description , $ this ->codes ['forbidden ' ], $ code , $ message );
211
211
}
212
212
213
213
/**
214
214
* Used when a specified resource cannot be found.
215
215
*
216
- * @return mixed
216
+ * @return Response
217
217
*/
218
- public function failNotFound (string $ description = 'Not Found ' , ?string $ code = null , string $ message = '' )
218
+ protected function failNotFound (string $ description = 'Not Found ' , ?string $ code = null , string $ message = '' )
219
219
{
220
220
return $ this ->fail ($ description , $ this ->codes ['resource_not_found ' ], $ code , $ message );
221
221
}
222
222
223
223
/**
224
224
* Used when the data provided by the client cannot be validated.
225
225
*
226
- * @return mixed
226
+ * @return Response
227
227
*
228
228
* @deprecated Use failValidationErrors instead
229
229
*/
230
- public function failValidationError (string $ description = 'Bad Request ' , ?string $ code = null , string $ message = '' )
230
+ protected function failValidationError (string $ description = 'Bad Request ' , ?string $ code = null , string $ message = '' )
231
231
{
232
232
return $ this ->fail ($ description , $ this ->codes ['invalid_data ' ], $ code , $ message );
233
233
}
@@ -237,19 +237,19 @@ public function failValidationError(string $description = 'Bad Request', ?string
237
237
*
238
238
* @param string|string[] $errors
239
239
*
240
- * @return mixed
240
+ * @return Response
241
241
*/
242
- public function failValidationErrors ($ errors , ?string $ code = null , string $ message = '' )
242
+ protected function failValidationErrors ($ errors , ?string $ code = null , string $ message = '' )
243
243
{
244
244
return $ this ->fail ($ errors , $ this ->codes ['invalid_data ' ], $ code , $ message );
245
245
}
246
246
247
247
/**
248
248
* Use when trying to create a new resource and it already exists.
249
249
*
250
- * @return mixed
250
+ * @return Response
251
251
*/
252
- public function failResourceExists (string $ description = 'Conflict ' , ?string $ code = null , string $ message = '' )
252
+ protected function failResourceExists (string $ description = 'Conflict ' , ?string $ code = null , string $ message = '' )
253
253
{
254
254
return $ this ->fail ($ description , $ this ->codes ['resource_exists ' ], $ code , $ message );
255
255
}
@@ -259,19 +259,19 @@ public function failResourceExists(string $description = 'Conflict', ?string $co
259
259
* Not Found, because here we know the data previously existed, but is now gone,
260
260
* where Not Found means we simply cannot find any information about it.
261
261
*
262
- * @return mixed
262
+ * @return Response
263
263
*/
264
- public function failResourceGone (string $ description = 'Gone ' , ?string $ code = null , string $ message = '' )
264
+ protected function failResourceGone (string $ description = 'Gone ' , ?string $ code = null , string $ message = '' )
265
265
{
266
266
return $ this ->fail ($ description , $ this ->codes ['resource_gone ' ], $ code , $ message );
267
267
}
268
268
269
269
/**
270
270
* Used when the user has made too many requests for the resource recently.
271
271
*
272
- * @return mixed
272
+ * @return Response
273
273
*/
274
- public function failTooManyRequests (string $ description = 'Too Many Requests ' , ?string $ code = null , string $ message = '' )
274
+ protected function failTooManyRequests (string $ description = 'Too Many Requests ' , ?string $ code = null , string $ message = '' )
275
275
{
276
276
return $ this ->fail ($ description , $ this ->codes ['too_many_requests ' ], $ code , $ message );
277
277
}
@@ -285,7 +285,7 @@ public function failTooManyRequests(string $description = 'Too Many Requests', ?
285
285
*
286
286
* @return Response The value of the Response's send() method.
287
287
*/
288
- public function failServerError (string $ description = 'Internal Server Error ' , ?string $ code = null , string $ message = '' ): Response
288
+ protected function failServerError (string $ description = 'Internal Server Error ' , ?string $ code = null , string $ message = '' ): Response
289
289
{
290
290
return $ this ->fail ($ description , $ this ->codes ['server_error ' ], $ code , $ message );
291
291
}
@@ -346,7 +346,7 @@ protected function format($data = null)
346
346
*
347
347
* @return $this
348
348
*/
349
- public function setResponseFormat (?string $ format = null )
349
+ protected function setResponseFormat (?string $ format = null )
350
350
{
351
351
$ this ->format = strtolower ($ format );
352
352
0 commit comments