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