middleware(function ($request, $next) { $this->form = PlanForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('crm.plan.modules'), 'plan', guard_url('plan')); return $next($request); }); } /** * Display a list of plan. * * @return Response */ public function index(PlanResourceRequest $request) { $request = $request->all(); $page = PlanActions::run('paginate', $request); $data = new PlansCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('plan::plan.names')) ->view('plan::plan.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display plan. * * @param Request $request * @param Model $plan * * @return Response */ public function show(PlanResourceRequest $request, Plan $model) { $form = $this->form; $modules = $this->modules; $data = new PlanResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('plan::plan.name')) ->data(compact('data', 'form', 'modules')) ->view('plan::plan.show') ->output(); } /** * Show the form for creating a new plan. * * @param Request $request * * @return Response */ public function create(PlanResourceRequest $request, Plan $model) { $form = $this->form; $modules = $this->modules; $data = new PlanResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('plan::plan.name')) ->view('plan::plan.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new plan. * * @param Request $request * * @return Response */ public function store(PlanResourceRequest $request, Plan $model) { try { $request = $request->all(); $model = PlanAction::run('store', $model, $request); $data = new PlanResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('plan::plan.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('plan/plan/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/plan/plan')) ->redirect(); } } /** * Show plan for editing. * * @param Request $request * @param Model $plan * * @return Response */ public function edit(PlanResourceRequest $request, Plan $model) { $form = $this->form; $modules = $this->modules; $data = new PlanResource($model); // return view('plan::plan.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('plan::plan.name')) ->view('plan::plan.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the plan. * * @param Request $request * @param Model $plan * * @return Response */ public function update(PlanResourceRequest $request, Plan $model) { try { $request = $request->all(); $model = PlanAction::run('update', $model, $request); $data = new PlanResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('plan::plan.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('plan/plan/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('plan/plan/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the plan. * * @param Model $plan * * @return Response */ public function destroy(PlanResourceRequest $request, Plan $model) { try { $request = $request->all(); $model = PlanAction::run('destroy', $model, $request); $data = new PlanResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('plan::plan.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('plan/plan/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('plan/plan/' . $model->getRouteKey())) ->redirect(); } } }