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