/** * Should have a belongs-to-many relationship with Images. */ public function testImages() { $images = $this->product->images(); $this->assertInstanceOf(BelongsToMany::class, $images); $this->assertEquals('images', $images->getRelationName()); }
/** * @param Product $product * * @return Image */ protected function attachImageToProduct(Product $product) : Image { $image = Image::create(['alt_text' => str_random(), 'url' => $this->generator()->anySlug()]); $product->images()->attach($image->id); return $image; }