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