/** * POST /api/foods * @param Request $request * @return Response */ public function store(Request $request) { $food = new Food($request->only(['name'])); $food->user()->associate(Auth::user()); $food->save(); $food = $this->transform($this->createItem($food, new FoodTransformer()))['data']; return response($food, Response::HTTP_CREATED); }
/** * */ private function insertFoods() { foreach (Config::get('foods.userOne') as $tempFood) { $food = new Food(['name' => $tempFood['name']]); $food->user()->associate($this->user); $food->save(); $this->attachUnits($food, $tempFood); $this->attachDefaultUnit($food, $tempFood); $food->save(); } }
/** * @test * @return void */ public function it_can_delete_a_food() { $this->logInUser(); $food = new Food(['name' => 'echidna']); $food->user()->associate($this->user); $food->save(); $this->seeInDatabase('foods', ['name' => 'echidna']); $response = $this->call('DELETE', '/api/foods/' . $food->id); $this->assertEquals(204, $response->getStatusCode()); $this->missingFromDatabase('foods', ['name' => 'echidna']); $response = $this->call('DELETE', '/api/foods/' . $food->id); $this->assertEquals(404, $response->getStatusCode()); }