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