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