repository = $plan; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Moblyze\FinancialPlan\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\FinancialPlan\Repositories\Presenter\PlanPresenter::class) ->$function(); } $plans = $this->repository->paginate(); return $this->response->setMetaTitle(trans('financial_plan::plan.names')) ->view('financial_plan::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 = 'financial_plan::plan.show'; } else { $view = 'financial_plan::plan.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('financial_plan::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('financial_plan::plan.name')) ->view('financial_plan::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('financial_plan::plan.name')])) ->code(204) ->status('success') ->url(guard_url('financial_plan/plan/' . $plan->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/financial_plan/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('financial_plan::plan.name')) ->view('financial_plan::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('financial_plan::plan.name')])) ->code(204) ->status('success') ->url(guard_url('financial_plan/plan/' . $plan->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('financial_plan/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('financial_plan::plan.name')])) ->code(202) ->status('success') ->url(guard_url('financial_plan/plan/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('financial_plan/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('financial_plan::plan.name')])) ->status("success") ->code(202) ->url(guard_url('financial_plan/plan')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/financial_plan/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('financial_plan::plan.name')])) ->status("success") ->code(202) ->url(guard_url('/financial_plan/plan')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/financial_plan/plan/')) ->redirect(); } } }