app/Http/Controllers/GameController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(GameRequest $request, StartGameService $startGameService)
    {
        $game = $this->repository->create([
            'owner_id' => $request->user()->id
        ]);
        $users = collect($request->players)->push($request->user()->id)->unique()->toArray();
        $game->addPlayers($users);
        $startGameService->setGame($game)->start();
        $game->fresh();
        $game->loadCount(['players','turns', 'pool']);
        $game->load(['players', 'turns']);
        return new GameResource($game);
    }
public function store ( GameRequest $ request , StartGameService $ startGameService ) { $ game = $ this -> repository -> create ( [ 'owner_id' => $ request -> user ( ) -> id ] ) ; $ users = collect ( $ request -> players ) -> push ( $ request -> user ( ) -> id ) -> unique ( ) -> toArray ( ) ; $ game -> addPlayers ( $ users ) ; $ startGameService -> setGame ( $ game ) -> start ( ) ; $ game -> fresh ( ) ; $ game -> loadCount ( [ 'players' , 'turns' , 'pool' ] ) ; $ game -> load ( [ 'players' , 'turns' ] ) ; return new GameResource ( $ game ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
/**
         * The creator of the game will always be a player and make sure that all ids are unique
         */