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