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