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