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