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