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