repository = $document; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Document\Repositories\Criteria\DocumentResourceCriteria::class); } /** * Display a list of document. * * @return Response */ public function index(DocumentRequest $request) { return $this->repository ->setPresenter(\Litecms\Document\Repositories\Presenter\DocumentPresenter::class) ->paginate(); } /** * Display document. * * @param Request $request * @param Model $document * * @return Response */ public function show(DocumentRequest $request, Document $document) { return $document->setPresenter(\Litecms\Document\Repositories\Presenter\DocumentListPresenter::class); ; } /** * Create new document. * * @param Request $request * * @return Response */ public function store(DocumentRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('document::document.name')]); $code = 204; $status = 'success'; $url = guard_url('document/document/' . $document->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('document/document'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the document. * * @param Request $request * @param Model $document * * @return Response */ public function update(DocumentRequest $request, Document $document) { try { $data = $request->all(); $document->update($data); $message = trans('messages.success.updated', ['Module' => trans('document::document.name')]); $code = 204; $status = 'success'; $url = guard_url('document/document/' . $document->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('document/document/' . $document->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the document. * * @param Model $document * * @return Response */ public function destroy(DocumentRequest $request, Document $document) { try { $document->delete(); $message = trans('messages.success.deleted', ['Module' => trans('document::document.name')]); $code = 202; $status = 'success'; $url = guard_url('document/document/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('document/document/' . $document->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }