repository = $note; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Note\Repositories\Criteria\NoteResourceCriteria::class); } /** * Display a list of note. * * @return Response */ public function index(NoteRequest $request) { return $this->repository ->setPresenter(\Bixo\Note\Repositories\Presenter\NotePresenter::class) ->paginate(); } /** * Display note. * * @param Request $request * @param Model $note * * @return Response */ public function show(NoteRequest $request, Note $note) { return $note->setPresenter(\Bixo\Note\Repositories\Presenter\NoteListPresenter::class); ; } /** * Create new note. * * @param Request $request * * @return Response */ public function store(NoteRequest $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('note::note.name')]); $code = 204; $status = 'success'; $url = guard_url('note/note/' . $note->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('note/note'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the note. * * @param Request $request * @param Model $note * * @return Response */ public function update(NoteRequest $request, Note $note) { try { $data = $request->all(); $note->update($data); $message = trans('messages.success.updated', ['Module' => trans('note::note.name')]); $code = 204; $status = 'success'; $url = guard_url('note/note/' . $note->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('note/note/' . $note->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the note. * * @param Model $note * * @return Response */ public function destroy(NoteRequest $request, Note $note) { try { $note->delete(); $message = trans('messages.success.deleted', ['Module' => trans('note::note.name')]); $code = 202; $status = 'success'; $url = guard_url('note/note/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('note/note/' . $note->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); } }