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