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