repository = $newproduct; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Newproduct\Repositories\Criteria\NewproductResourceCriteria::class); } /** * Display a list of newproduct. * * @return Response */ public function index(NewproductRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\Newproduct\Repositories\Presenter\NewproductPresenter::class) ->$function(); } $newproducts = $this->repository->paginate(); return $this->response->title(trans('newproduct::newproduct.names')) ->view('newproduct::newproduct.index', true) ->data(compact('newproducts')) ->output(); } /** * Display newproduct. * * @param Request $request * @param Model $newproduct * * @return Response */ public function show(NewproductRequest $request, Newproduct $newproduct) { if ($newproduct->exists) { $view = 'newproduct::newproduct.show'; } else { $view = 'newproduct::newproduct.new'; } return $this->response->title(trans('app.view') . ' ' . trans('newproduct::newproduct.name')) ->data(compact('newproduct')) ->view($view, true) ->output(); } /** * Show the form for creating a new newproduct. * * @param Request $request * * @return Response */ public function create(NewproductRequest $request) { $newproduct = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('newproduct::newproduct.name')) ->view('newproduct::newproduct.create', true) ->data(compact('newproduct')) ->output(); } /** * Create new newproduct. * * @param Request $request * * @return Response */ public function store(NewproductRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $newproduct = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('newproduct::newproduct.name')])) ->code(204) ->status('success') ->url(guard_url('newproduct/newproduct/' . $newproduct->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/newproduct/newproduct')) ->redirect(); } } /** * Show newproduct for editing. * * @param Request $request * @param Model $newproduct * * @return Response */ public function edit(NewproductRequest $request, Newproduct $newproduct) { return $this->response->title(trans('app.edit') . ' ' . trans('newproduct::newproduct.name')) ->view('newproduct::newproduct.edit', true) ->data(compact('newproduct')) ->output(); } /** * Update the newproduct. * * @param Request $request * @param Model $newproduct * * @return Response */ public function update(NewproductRequest $request, Newproduct $newproduct) { try { $attributes = $request->all(); $newproduct->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('newproduct::newproduct.name')])) ->code(204) ->status('success') ->url(guard_url('newproduct/newproduct/' . $newproduct->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('newproduct/newproduct/' . $newproduct->getRouteKey())) ->redirect(); } } /** * Remove the newproduct. * * @param Model $newproduct * * @return Response */ public function destroy(NewproductRequest $request, Newproduct $newproduct) { try { $newproduct->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('newproduct::newproduct.name')])) ->code(202) ->status('success') ->url(guard_url('newproduct/newproduct/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('newproduct/newproduct/' . $newproduct->getRouteKey())) ->redirect(); } } /** * Remove multiple newproduct. * * @param Model $newproduct * * @return Response */ public function delete(NewproductRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('newproduct::newproduct.name')])) ->status("success") ->code(202) ->url(guard_url('newproduct/newproduct')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/newproduct/newproduct')) ->redirect(); } } /** * Restore deleted newproducts. * * @param Model $newproduct * * @return Response */ public function restore(NewproductRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('newproduct::newproduct.name')])) ->status("success") ->code(202) ->url(guard_url('/newproduct/newproduct')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/newproduct/newproduct/')) ->redirect(); } } }