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