@@ -43,7 +43,7 @@ abstract class BaseController extends LaravelController
4343 /**
4444 * Do we need to unguard the model before create/update?
4545 *
46- * @var boolean
46+ * @var bool
4747 */
4848 protected $ unguard = false ;
4949
@@ -54,10 +54,9 @@ public function __construct()
5454 {
5555 $ this ->model = $ this ->model ();
5656 $ this ->transformer = $ this ->transformer ();
57- $ this ->fractal = new Manager ;
57+ $ this ->fractal = new Manager () ;
5858
59- if (Input::has ('include ' ))
60- {
59+ if (Input::has ('include ' )) {
6160 $ this ->fractal ->parseIncludes (camel_case (Input::get ('include ' )));
6261 }
6362 }
@@ -134,7 +133,6 @@ protected function respondWithCollection($collection, $callback)
134133 return $ this ->respondWithArray ($ rootScope ->toArray ());
135134 }
136135
137-
138136 /**
139137 * Respond with a given array of items.
140138 *
@@ -161,14 +159,15 @@ protected function respondWithError($message)
161159 'error ' => [
162160 'http_code ' => $ this ->statusCode ,
163161 'message ' => $ message ,
164- ]
162+ ],
165163 ]);
166164 }
167165
168166 /**
169167 * Prepare root scope and adds meta.
170168 *
171169 * @param Item $resource
170+ *
172171 * @return mixed
173172 */
174173 protected function prepareRootScope ($ resource )
@@ -196,6 +195,7 @@ protected function rulesForCreate()
196195 * Get the validation rules for update.
197196 *
198197 * @param $id
198+ *
199199 * @return array
200200 */
201201 protected function rulesForUpdate ($ id )
@@ -208,7 +208,7 @@ protected function rulesForUpdate($id)
208208 *
209209 * @param $message
210210 *
211- * @return Response
211+ * @return Response
212212 */
213213 public function errorForbidden ($ message = 'Forbidden ' )
214214 {
@@ -220,7 +220,7 @@ public function errorForbidden($message = 'Forbidden')
220220 *
221221 * @param $message
222222 *
223- * @return Response
223+ * @return Response
224224 */
225225 public function errorInternalError ($ message = 'Internal Error ' )
226226 {
@@ -232,7 +232,7 @@ public function errorInternalError($message = 'Internal Error')
232232 *
233233 * @param $message
234234 *
235- * @return Response
235+ * @return Response
236236 */
237237 public function errorNotFound ($ message = 'Resource Not Found ' )
238238 {
@@ -244,7 +244,7 @@ public function errorNotFound($message = 'Resource Not Found')
244244 *
245245 * @param $message
246246 *
247- * @return Response
247+ * @return Response
248248 */
249249 public function errorUnauthorized ($ message = 'Unauthorized ' )
250250 {
@@ -256,7 +256,7 @@ public function errorUnauthorized($message = 'Unauthorized')
256256 *
257257 * @param $message
258258 *
259- * @return Response
259+ * @return Response
260260 */
261261 public function errorWrongArgs ($ message = 'Wrong Arguments ' )
262262 {
@@ -268,7 +268,7 @@ public function errorWrongArgs($message = 'Wrong Arguments')
268268 *
269269 * @param $message
270270 *
271- * @return Response
271+ * @return Response
272272 */
273273 public function errorNotImplemented ($ message = 'Not implemented ' )
274274 {
@@ -277,32 +277,31 @@ public function errorNotImplemented($message = 'Not implemented')
277277
278278 /**
279279 * Display a listing of the resource.
280- * GET /api/{resource}
280+ * GET /api/{resource}.
281281 *
282282 * @return Response
283283 */
284284 public function index ()
285285 {
286- $ with = $ this ->getEagerLoad ();
286+ $ with = $ this ->getEagerLoad ();
287287 $ items = $ this ->model ->with ($ with )->get ();
288288
289289 return $ this ->respondWithCollection ($ items , $ this ->transformer );
290290 }
291291
292292 /**
293293 * Store a newly created resource in storage.
294- * POST /api/{resource}
294+ * POST /api/{resource}.
295295 *
296296 * @return Response
297297 */
298298 public function store ()
299299 {
300300 $ input = Input::json ();
301- $ data = $ input ->get ('data ' );
301+ $ data = $ input ->get ('data ' );
302302
303303 $ v = Validator::make ($ data , $ this ->rulesForCreate ());
304- if ($ v ->fails ())
305- {
304+ if ($ v ->fails ()) {
306305 return $ this ->errorWrongArgs ('Validation failed ' );
307306 }
308307
@@ -315,9 +314,9 @@ public function store()
315314
316315 /**
317316 * Display the specified resource.
318- * GET /api/{resource}/{id}
317+ * GET /api/{resource}/{id}.
319318 *
320- * @param int $id
319+ * @param int $id
321320 *
322321 * @return Response
323322 */
@@ -326,8 +325,7 @@ public function show($id)
326325 $ with = $ this ->getEagerLoad ();
327326
328327 $ item = $ this ->findItem ($ id , $ with );
329- if (!$ item )
330- {
328+ if (!$ item ) {
331329 return $ this ->errorNotFound ();
332330 }
333331
@@ -336,31 +334,28 @@ public function show($id)
336334
337335 /**
338336 * Update the specified resource in storage.
339- * PUT /api/{resource}/{id}
337+ * PUT /api/{resource}/{id}.
340338 *
341- * @param int $id
339+ * @param int $id
342340 *
343341 * @return Response
344342 */
345343 public function update ($ id )
346344 {
347345 $ input = Input::json ();
348- $ data = $ input ->get ('data ' );
346+ $ data = $ input ->get ('data ' );
349347
350- if (!$ data )
351- {
348+ if (!$ data ) {
352349 return $ this ->errorWrongArgs ('Empty data ' );
353350 }
354351
355352 $ item = $ this ->findItem ($ id );
356- if (!$ item )
357- {
353+ if (!$ item ) {
358354 return $ this ->errorNotFound ();
359355 }
360356
361357 $ v = Validator::make ($ data , $ this ->rulesForUpdate ($ item ->id ));
362- if ($ v ->fails ())
363- {
358+ if ($ v ->fails ()) {
364359 return $ this ->errorWrongArgs ('Validation failed ' );
365360 }
366361
@@ -374,18 +369,17 @@ public function update($id)
374369
375370 /**
376371 * Remove the specified resource from storage.
377- * DELETE /api/{resource}/{id}
372+ * DELETE /api/{resource}/{id}.
378373 *
379- * @param int $id
374+ * @param int $id
380375 *
381376 * @return Response
382377 */
383378 public function destroy ($ id )
384379 {
385380 $ item = $ this ->findItem ($ id );
386381
387- if (!$ item )
388- {
382+ if (!$ item ) {
389383 return $ this ->errorNotFound ();
390384 }
391385
@@ -407,7 +401,8 @@ public function create()
407401 /**
408402 * Show the form for editing the specified resource.
409403 *
410- * @param int $id
404+ * @param int $id
405+ *
411406 * @return Response
412407 */
413408 public function edit ($ id )
@@ -422,7 +417,7 @@ public function edit($id)
422417 */
423418 protected function getEagerLoad ()
424419 {
425- $ include = camel_case (Input::get ('include ' , '' ));
420+ $ include = camel_case (Input::get ('include ' , '' ));
426421 $ includes = explode (', ' , $ include );
427422 $ includes = array_filter ($ includes );
428423
@@ -439,8 +434,7 @@ protected function getEagerLoad()
439434 */
440435 protected function findItem ($ id , array $ with = [])
441436 {
442- if (Input::has ('use_as_id ' ))
443- {
437+ if (Input::has ('use_as_id ' )) {
444438 return $ this ->model ->with ($ with )->where (Input::get ('use_as_id ' ), '= ' , $ id )->first ();
445439 }
446440
@@ -452,9 +446,8 @@ protected function findItem($id, array $with = [])
452446 */
453447 protected function unguardIfNeeded ()
454448 {
455- if ($ this ->unguard )
456- {
449+ if ($ this ->unguard ) {
457450 $ this ->model ->unguard ();
458451 }
459452 }
460- }
453+ }
0 commit comments