repository = $goal; parent::__construct(); } /** * Display a list of goal. * * @return Response */ public function index(GoalRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('goal::goal.names').' :: '); return $this->theme->of('goal::admin.goal.index')->render(); } /** * Display a list of goal. * * @return Response */ public function getJson(GoalRequest $request) { $pageLimit = $request->input('pageLimit'); $goals = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Goal\\Goal\\Repositories\\Presenter\\GoalListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $goals['recordsTotal'] = $goals['meta']['pagination']['total']; $goals['recordsFiltered'] = $goals['meta']['pagination']['total']; $goals['request'] = $request->all(); return response()->json($goals, 200); } /** * Display goal. * * @param Request $request * @param Model $goal * * @return Response */ public function show(GoalRequest $request, Goal $goal) { if (!$goal->exists) { return response()->view('goal::admin.goal.new', compact('goal')); } Form::populate($goal); return response()->view('goal::admin.goal.show', compact('goal')); } /** * Show the form for creating a new goal. * * @param Request $request * * @return Response */ public function create(GoalRequest $request) { $goal = $this->repository->newInstance([]); Form::populate($goal); return response()->view('goal::admin.goal.create', compact('goal')); } /** * Create new goal. * * @param Request $request * * @return Response */ public function store(GoalRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $goal = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('goal::goal.name')]), 'code' => 204, 'redirect' => trans_url('/admin/goal/goal/'.$goal->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show goal for editing. * * @param Request $request * @param Model $goal * * @return Response */ public function edit(GoalRequest $request, Goal $goal) { Form::populate($goal); return response()->view('goal::admin.goal.edit', compact('goal')); } /** * Update the goal. * * @param Request $request * @param Model $goal * * @return Response */ public function update(GoalRequest $request, Goal $goal) { try { $attributes = $request->all(); $goal->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('goal::goal.name')]), 'code' => 204, 'redirect' => trans_url('/admin/goal/goal/'.$goal->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/goal/goal/'.$goal->getRouteKey()), ], 400); } } /** * Remove the goal. * * @param Model $goal * * @return Response */ public function destroy(GoalRequest $request, Goal $goal) { try { $t = $goal->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('goal::goal.name')]), 'code' => 202, 'redirect' => trans_url('/admin/goal/goal/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/goal/goal/'.$goal->getRouteKey()), ], 400); } } }