form = FileForm::setAttributes()->toArray(); $this->modules = $this->modules(config('files.file.modules'), 'file', guard_url('file')); $this->repository = $file; } /** * Display a list of file. * * @return Response */ public function index(FileRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(FileResourceFilter::class) ->setPresenter(FileListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('file::file.names')) ->view('file::file.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display file. * * @param Request $request * @param Model $file * * @return Response */ public function show(FileRequest $request, FileRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('file::file.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('file::file.show') ->output(); } /** * Show the form for creating a new file. * * @param Request $request *x * @return Response */ public function create(FileRequest $request, FileRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('file::file.name')) ->view('file::file.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new file. * * @param Request $request * * @return Response */ public function store(FileRequest $request, FileRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('file::file.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('file/file/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/file/file')) ->redirect(); } } /** * Show file for editing. * * @param Request $request * @param Model $file * * @return Response */ public function edit(FileRequest $request, FileRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('file::file.name')) ->view('file::file.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the file. * * @param Request $request * @param Model $file * * @return Response */ public function update(FileRequest $request, FileRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('file::file.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('file/file/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('file/file/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the file. * * @param Model $file * * @return Response */ public function destroy(FileRequest $request, FileRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('file::file.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('file/file/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('file/file/' . $repository->getRouteKey())) ->redirect(); } } }