public function testDeleteSuccess() { $product = factory(Product::class)->create(); $user = factory(App\User::class)->make(['hasRole' => true]); Auth::login($user); $res = $this->call('DELETE', "/products/{$product->id}"); $this->assertEquals(204, $res->getStatusCode()); $exists = Product::find($product->id); $this->assertNull($exists); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // check authenticate if (!$this->checkAuth()) { return response()->json(null, 401); } // check permission if (!$this->checkPermission('delete-product')) { return response()->json(null, 403); } // retrieve product $product = Product::find($id); // check exists if (empty($product)) { return response()->json(null, 404); } if (!$product->delete()) { return response()->json(null, 500); } return response()->json(null, 204); }