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