示例#1
0
 /**
  * Get all cars of myself
  * GET /api/users/self/cars
  *
  * @return Response
  */
 public function selfCars()
 {
     $user = Auth::user();
     $cars = $user->cars();
     if ($cars->exists()) {
         return $this->respond($this->collectionTransformer->transformCars($cars));
     }
     return $this->respondNotFound('No cars');
 }
示例#2
0
 public function users($type, $id)
 {
     $usersIDs = Like::usersIDs($this->str($type), $id);
     if ($usersIDs->count() == 0) {
         return $this->respond([]);
     }
     $users = User::whereIn('id', $usersIDs->toArray())->with('cars')->get();
     if (!$users) {
         return $this->respond([]);
     }
     $response = $users->map(function ($user) {
         $rsp = $this->collectionTransformer->transformUserToSmall($user);
         $rsp['cars'] = $this->collectionTransformer->transformCars($user->cars);
         return $rsp;
     });
     return $this->respond($response);
 }