/** * Show jobs of Agent * @return \Illuminate\Http\JsonResponse */ public function jobs($agentId) { try { // $agent = Agent::with('user', 'user.jobs', 'user.jobs.client')->findOrFail($agentId); // return $this->respondWithCollection($agent, new AgentTransformer); // return $this->respondWithArray(['success' => true, 'data' => $agent->getTransformed(new AgentTransformer, ['jobs', 'jobs.client', 'user'])]); $agent = Agent::findOrFail($agentId); $jobs = User::findOrFail($agent->user_id)->jobs()->with('client')->paginate(); return $this->respondWithCollection($jobs, new JobTransformer(), ['client']); } catch (ModelNotFoundException $e) { return $this->setStatusCode(404)->respondWithError('Agent with ID ' . $agentId . ' Not found', 404); } }