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) { return $this->repository ->setPresenter(\Kscc\Tender\Repositories\Presenter\TenderPresenter::class) ->paginate(); } /** * Display tender. * * @param Request $request * @param Model $tender * * @return Response */ public function show(TenderRequest $request, Tender $tender) { return $tender->setPresenter(\Kscc\Tender\Repositories\Presenter\TenderListPresenter::class); ; } /** * Create new tender. * * @param Request $request * * @return Response */ public function store(TenderRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('tender::tender.name')]); $code = 204; $status = 'success'; $url = guard_url('tender/tender/' . $tender->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('tender/tender'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the tender. * * @param Request $request * @param Model $tender * * @return Response */ public function update(TenderRequest $request, Tender $tender) { try { $data = $request->all(); $tender->update($data); $message = trans('messages.success.updated', ['Module' => trans('tender::tender.name')]); $code = 204; $status = 'success'; $url = guard_url('tender/tender/' . $tender->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('tender/tender/' . $tender->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the tender. * * @param Model $tender * * @return Response */ public function destroy(TenderRequest $request, Tender $tender) { try { $tender->delete(); $message = trans('messages.success.deleted', ['Module' => trans('tender::tender.name')]); $code = 202; $status = 'success'; $url = guard_url('tender/tender/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('tender/tender/' . $tender->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }