middleware(function ($request, $next) { $this->form = DownloadForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.download.modules'), 'download', guard_url('download')); 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('download::download.names')) ->view('download::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('download::download.name')) ->data(compact('data', 'form', 'modules')) ->view('download::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('download::download.name')) ->view('download::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('download::download.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('download/download/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/download/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('download::download.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('download::download.name')) ->view('download::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('download::download.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('download/download/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('download/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('download::download.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('download/download/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('download/download/' . $model->getRouteKey())) ->redirect(); } } }