middleware('web'); $this->middleware('auth:admin.web'); $this->setupTheme(config('theme.themes.admin.theme'), config('theme.themes.admin.layout')); $this->repository = $tender; parent::__construct(); } /** * Display a list of tender. * * @return Response */ public function index(TenderAdminWebRequest $request) { $pageLimit = $request->input('pageLimit'); if ($request->wantsJson()) { $tenders = $this->repository ->pushCriteria(new \Litecms\Tender\Repositories\Criteria\TenderAdminCriteria()) ->setPresenter('\\Litecms\\Tender\\Repositories\\Presenter\\TenderListPresenter') ->scopeQuery(function ($query) { return $query->orderBy('id', 'DESC'); })->paginate($pageLimit); $tenders['recordsTotal'] = $tenders['meta']['pagination']['total']; $tenders['recordsFiltered'] = $tenders['meta']['pagination']['total']; $tenders['request'] = $request->all(); return response()->json($tenders, 200); } $this ->theme->prependTitle(trans('tender::tender.names').' :: '); return $this->theme->of('tender::admin.tender.index')->render(); } /** * Display tender. * * @param Request $request * @param Model $tender * * @return Response */ public function show(TenderAdminWebRequest $request, Tender $tender) { if (!$tender->exists) { return response()->view('tender::admin.tender.new', compact('tender')); } Form::populate($tender); return response()->view('tender::admin.tender.show', compact('tender')); } /** * Show the form for creating a new tender. * * @param Request $request * * @return Response */ public function create(TenderAdminWebRequest $request) { $tender = $this->repository->newInstance([]); Form::populate($tender); return response()->view('tender::admin.tender.create', compact('tender')); } /** * Create new tender. * * @param Request $request * * @return Response */ public function store(TenderAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $tender = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('tender::tender.name')]), 'code' => 204, 'redirect' => trans_url('/admin/tender/tender/'.$tender->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show tender for editing. * * @param Request $request * @param Model $tender * * @return Response */ public function edit(TenderAdminWebRequest $request, Tender $tender) { Form::populate($tender); return response()->view('tender::admin.tender.edit', compact('tender')); } /** * Update the tender. * * @param Request $request * @param Model $tender * * @return Response */ public function update(TenderAdminWebRequest $request, Tender $tender) { try { $attributes = $request->all(); $tender->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('tender::tender.name')]), 'code' => 204, 'redirect' => trans_url('/admin/tender/tender/'.$tender->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/tender/tender/'.$tender->getRouteKey()), ], 400); } } /** * Remove the tender. * * @param Model $tender * * @return Response */ public function destroy(TenderAdminWebRequest $request, Tender $tender) { try { $t = $tender->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('tender::tender.name')]), 'code' => 202, 'redirect' => trans_url('/admin/tender/tender/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/tender/tender/'.$tender->getRouteKey()), ], 400); } } }