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