form = FileForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('media_files.media_file.modules'), 'media_file', guard_url('media_file')); } /** * Display a list of file. * * @return Response */ public function index(FileRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = File::pushScope(new RequestScope()) ->pushScope(new FileResourceScope()) ->simplePaginate($pageLimit); $data = new FilesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('media_file::file.names')) ->view('media_file::file.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display file. * * @param Request $request * @param Model $file * * @return Response */ public function show(FileRequest $request, File $model) { $form = $this->form; $modules = $this->modules; $data = new FileResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('media_file::file.name')) ->data(compact('data', 'form', 'modules')) ->view('media_file::file.show') ->output(); } /** * Show the form for creating a new file. * * @param Request $request * * @return Response */ public function create(FileRequest $request, File $model) { $form = $this->form; $modules = $this->modules; $data = new FileResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('media_file::file.name')) ->view('media_file::file.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new file. * * @param Request $request * * @return Response */ public function store(FileRequest $request, File $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new FileResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('media_file::file.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('media_file/file/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/media_file/file')) ->redirect(); } } /** * Show file for editing. * * @param Request $request * @param Model $file * * @return Response */ public function edit(FileRequest $request, File $model) { $form = $this->form; $modules = $this->modules; $data = new FileResource($model); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('media_file::file.name')) ->view('media_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, File $model) { try { $attributes = $request->all(); $model = $model->update($attributes); $data = new FileResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('media_file::file.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('media_file/file/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('media_file/file/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the file. * * @param Model $file * * @return Response */ public function destroy(FileRequest $request, File $model) { try { $model->delete(); $data = new FileResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('media_file::file.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('media_file/file/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('media_file/file/' . $model->getRouteKey())) ->redirect(); } } }