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