repository = $plan; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Moblyze\Checklist\Repositories\Criteria\PlanResourceCriteria::class); } /** * Display a list of plan. * * @return Response */ public function index(PlanRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Moblyze\Checklist\Repositories\Presenter\PlanPresenter::class) ->$function(); } $plans = $this->repository->paginate(); return $this->response->setMetaTitle(trans('checklist::plan.names')) ->view('checklist::plan.index', true) ->data(compact('plans', 'view')) ->output(); } /** * Display plan. * * @param Request $request * @param Model $plan * * @return Response */ public function show(PlanRequest $request, Plan $plan) { if ($plan->exists) { $view = 'checklist::plan.show'; } else { $view = 'checklist::plan.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('checklist::plan.name')) ->data(compact('plan')) ->view($view, true) ->output(); } /** * Show the form for creating a new plan. * * @param Request $request * * @return Response */ public function create(PlanRequest $request) { $plan = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('checklist::plan.name')) ->view('checklist::plan.create', true) ->data(compact('plan')) ->output(); } /** * Create new plan. * * @param Request $request * * @return Response */ public function store(PlanRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $plan = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('checklist::plan.name')])) ->code(204) ->status('success') ->url(guard_url('checklist/plan/' . $plan->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/checklist/plan')) ->redirect(); } } /** * Show plan for editing. * * @param Request $request * @param Model $plan * * @return Response */ public function edit(PlanRequest $request, Plan $plan) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('checklist::plan.name')) ->view('checklist::plan.edit', true) ->data(compact('plan')) ->output(); } /** * Update the plan. * * @param Request $request * @param Model $plan * * @return Response */ public function update(PlanRequest $request, Plan $plan) { try { $attributes = $request->all(); $plan->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('checklist::plan.name')])) ->code(204) ->status('success') ->url(guard_url('checklist/plan/' . $plan->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('checklist/plan/' . $plan->getRouteKey())) ->redirect(); } } /** * Remove the plan. * * @param Model $plan * * @return Response */ public function destroy(PlanRequest $request, Plan $plan) { try { $plan->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('checklist::plan.name')])) ->code(202) ->status('success') ->url(guard_url('checklist/plan/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('checklist/plan/' . $plan->getRouteKey())) ->redirect(); } } /** * Remove multiple plan. * * @param Model $plan * * @return Response */ public function delete(PlanRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('checklist::plan.name')])) ->status("success") ->code(202) ->url(guard_url('checklist/plan')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/checklist/plan')) ->redirect(); } } /** * Restore deleted plans. * * @param Model $plan * * @return Response */ public function restore(PlanRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('checklist::plan.name')])) ->status("success") ->code(202) ->url(guard_url('/checklist/plan')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/checklist/plan/')) ->redirect(); } } }