user()->account->documents() ->orderBy($this->sort, $this->sortDirection) ->paginate($this->getLimitPerPage()); } catch (QueryException $e) { return $this->respondInvalidQuery(); } return DocumentResource::collection($documents); } /** * Get the list of documents for a specific contact. * * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\Http\JsonResponse */ public function documents(Request $request, $contactId) { try { Contact::where('account_id', auth()->user()->account_id) ->where('id', $contactId) ->firstOrFail(); } catch (ModelNotFoundException $e) { return $this->respondNotFound(); } try { $documents = auth()->user()->account->documents() ->where('contact_id', $contactId) ->orderBy($this->sort, $this->sortDirection) ->paginate($this->getLimitPerPage()); } catch (QueryException $e) { return $this->respondInvalidQuery(); } return DocumentResource::collection($documents); } /** * Get the detail of a given document. * * @param Request $request * * @return DocumentResource|\Illuminate\Http\JsonResponse */ public function show(Request $request, $documentId) { try { $document = Document::where('account_id', auth()->user()->account_id) ->findOrFail($documentId); } catch (ModelNotFoundException $e) { return $this->respondNotFound(); } return new DocumentResource($document); } }