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