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