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