コード例 #1
0
 public function update(TournamentLocationRequest $request, TournamentLocation $tournament_locations)
 {
     foreach ($request->all()['data']['attributes'] as $key => $value) {
         if (isset($tournament_locations->{$key})) {
             $tournament_locations->{$key} = $value;
         }
     }
     // fetch tournament
     $tournament = Tournament::findOrFail($request->all()['data']['relationships']['tournament']['data']['id']);
     $tournament_locations->tournament_id = $tournament->id;
     $tournament_locations->save();
     $resource = new Item($tournament_locations, new TournamentLocationTransformer(), 'tournament-feeds');
     return $this->fractal()->createData($resource)->toJson();
 }
コード例 #2
0
 public function testPatchTournamentLocations()
 {
     // create user info and convert it to json
     $location = factory(Location::class)->create();
     $tournament = factory(Tournament::class)->create(['location_id' => $location->id]);
     $tournamentLocationObject = factory(TournamentLocation::class)->create(['tournament_id' => $tournament->id]);
     $tournamentLocationObject->street = '9999 street name';
     $tournamentLocationData = json_encode(['data' => ['type' => 'tournament-locations', 'attributes' => $tournamentLocationObject->toArray(), 'relationships' => ['tournament' => ['data' => ['type' => 'tournaments', 'id' => $tournament->id]]]]]);
     $response = $this->callPatch(self::API_URL . $tournamentLocationObject->id, $tournamentLocationData);
     $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
     $this->assertNotNull($tournamentLocation = json_decode($response->getContent())->data);
     $this->assertNotEmpty($tournamentLocation->id);
     // test to make sure the user was created
     $updatedTournamentLocation = TournamentLocation::findOrFail($tournamentLocation->id);
     $this->assertEquals('9999 street name', $updatedTournamentLocation->street);
     $this->assertEquals($updatedTournamentLocation->tournament->toArray(), $tournament->toArray());
 }