repository = $supplier; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Backdoor\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(\Litecms\Backdoor\Repositories\Presenter\SupplierPresenter::class) ->$function(); } $suppliers = $this->repository->paginate(); return $this->response->title(trans('backdoor::supplier.names')) ->view('backdoor::supplier.index', true) ->data(compact('suppliers')) ->output(); } /** * Display supplier. * * @param Request $request * @param Model $supplier * * @return Response */ public function show(SupplierRequest $request, Supplier $supplier) { if ($supplier->exists) { $view = 'backdoor::supplier.show'; } else { $view = 'backdoor::supplier.new'; } return $this->response->title(trans('app.view') . ' ' . trans('backdoor::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->title(trans('app.new') . ' ' . trans('backdoor::supplier.name')) ->view('backdoor::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('backdoor::supplier.name')])) ->code(204) ->status('success') ->url(guard_url('backdoor/supplier/' . $supplier->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/backdoor/supplier')) ->redirect(); } } /** * Show supplier for editing. * * @param Request $request * @param Model $supplier * * @return Response */ public function edit(SupplierRequest $request, Supplier $supplier) { return $this->response->title(trans('app.edit') . ' ' . trans('backdoor::supplier.name')) ->view('backdoor::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('backdoor::supplier.name')])) ->code(204) ->status('success') ->url(guard_url('backdoor/supplier/' . $supplier->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('backdoor/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('backdoor::supplier.name')])) ->code(202) ->status('success') ->url(guard_url('backdoor/supplier/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('backdoor/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('backdoor::supplier.name')])) ->status("success") ->code(202) ->url(guard_url('backdoor/supplier')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/backdoor/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('backdoor::supplier.name')])) ->status("success") ->code(202) ->url(guard_url('/backdoor/supplier')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/backdoor/supplier/')) ->redirect(); } } }