repository = $game; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Game\Game\Repositories\Criteria\GameResourceCriteria::class); } /** * Display a list of game. * * @return Response */ public function index(GameRequest $request) { return $this->repository ->setPresenter(\Game\Game\Repositories\Presenter\GamePresenter::class) ->paginate(); } /** * Display game. * * @param Request $request * @param Model $game * * @return Response */ public function show(GameRequest $request, Game $game) { return $game->setPresenter(\Game\Game\Repositories\Presenter\GameListPresenter::class); ; } /** * Create new game. * * @param Request $request * * @return Response */ public function store(GameRequest $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('game::game.name')]); $code = 204; $status = 'success'; $url = guard_url('game/game/' . $game->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('game/game'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the game. * * @param Request $request * @param Model $game * * @return Response */ public function update(GameRequest $request, Game $game) { try { $data = $request->all(); $game->update($data); $message = trans('messages.success.updated', ['Module' => trans('game::game.name')]); $code = 204; $status = 'success'; $url = guard_url('game/game/' . $game->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('game/game/' . $game->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the game. * * @param Model $game * * @return Response */ public function destroy(GameRequest $request, Game $game) { try { $game->delete(); $message = trans('messages.success.deleted', ['Module' => trans('game::game.name')]); $code = 202; $status = 'success'; $url = guard_url('game/game/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('game/game/' . $game->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); } }