public function store(Request $req, JsonResponse $res) { $type = $req->json('data.type'); $attrs = $this->getAttrsFromRequest($req); if ($this->validateCreate($attrs)) { $gameScore = $this->gameScore->create($attrs); return new JsonResponse(['data' => $this->serializeGameScore($gameScore)]); } return new JsonResponse(['errors' => array_map(function ($err) { return ['status' => '400', 'title' => 'Invalid Attribute', 'detail' => $err]; }, $this->errors->all())], 400); }
public function testGameDelete() { GameScore::create(['username' => 'AAA', 'score' => 1000000, 'game' => $this->game->id]); GameScore::create(['username' => 'AAA', 'score' => 2000000, 'game' => $this->gameTwo->id]); $this->json('DELETE', 'game-scores/1'); $this->assertResponseStatus(204); $this->assertEquals(1, GameScore::count()); }
/** * Run the database seeds. * * @return void */ public function run() { GameScore::truncate(); $gameScores = [['username' => 'AAA', 'score' => 1000, 'game' => 1], ['username' => 'CDC', 'score' => 1500, 'game' => 1], ['username' => 'RFT', 'score' => 2000, 'game' => 1]]; foreach ($gameScores as $gameScore) { GameScore::create($gameScore); } }