collect(['issued_at'=> 'desc']); return $this->response->paginator($documents, new Transformer()); } /** * Display the specified resource. * * @param $id * @return \Dingo\Api\Http\Response */ public function show($id) { // Check if we're querying by id or number if (is_numeric($id)) { $document = Document::find($id); } else { $document = Document::where('document_number', $id)->first(); } return $this->response->item($document, new Transformer()); } /** * Store a newly created resource in storage. * * @param $request * * @return \Dingo\Api\Http\Response */ public function store(Request $request) { $document = $this->dispatch(new CreateDocument($request)); return $this->response->created(route('api.documents.show', $document->id)); } /** * Update the specified resource in storage. * * @param $document * @param $request * * @return \Dingo\Api\Http\Response */ public function update(Document $document, Request $request) { $document = $this->dispatch(new UpdateDocument($document, $request)); return $this->response->item($document->fresh(), new Transformer()); } /** * Remove the specified resource from storage. * * @param Document $document * * @return \Dingo\Api\Http\Response */ public function destroy(Document $document) { try { $this->dispatch(new DeleteDocument($document)); return $this->response->noContent(); } catch(\Exception $e) { $this->response->errorUnauthorized($e->getMessage()); } } }