/** * * @param Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $unit = new Unit(['name' => $request->get('name'), 'for' => 'exercise']); $unit->user()->associate(Auth::user()); $unit->save(); return $this->responseCreatedWithTransformer($unit, new UnitTransformer()); }
/** * POST /api/units * @param Request $request * @return Response */ public function store(Request $request) { $unit = new Unit($request->only(['name'])); $unit->for = 'food'; $unit->user()->associate(Auth::user()); $unit->save(); $unit = $this->transform($this->createItem($unit, new UnitTransformer()))['data']; return response($unit, Response::HTTP_CREATED); }
/** * @test * @return void */ public function it_can_delete_an_exercise_unit() { $this->logInUser(); $unit = new Unit(['name' => 'echidna', 'for' => 'exercise']); $unit->user()->associate($this->user); $unit->save(); $this->seeInDatabase('units', ['name' => 'echidna']); $response = $this->call('DELETE', '/api/exerciseUnits/' . $unit->id); $this->assertEquals(204, $response->getStatusCode()); $this->missingFromDatabase('units', ['name' => 'echidna']); // @TODO Test the 404 for the other methods as well (show, update) $response = $this->call('DELETE', '/api/units/' . $unit->id); $this->assertEquals(404, $response->getStatusCode()); }