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