diff --git a/src/HasMedia.php b/src/HasMedia.php index e10041144..44cd55b8b 100644 --- a/src/HasMedia.php +++ b/src/HasMedia.php @@ -40,7 +40,7 @@ public function addMediaFromDisk(string $key, string $disk = null): FileAdder; */ public function copyMedia($file): FileAdder; - public function hasMedia(string $collectionMedia = ''): bool; + public function hasMedia(string $collectionName = ''): bool; /** * Get media collection by its collectionName. diff --git a/src/InteractsWithMedia.php b/src/InteractsWithMedia.php index 78ed6aeac..9928bbe3e 100644 --- a/src/InteractsWithMedia.php +++ b/src/InteractsWithMedia.php @@ -271,9 +271,9 @@ public function copyMedia($file): FileAdder /* * Determine if there is media in the given collection. */ - public function hasMedia(string $collectionName = 'default'): bool + public function hasMedia(string $collectionName = 'default', array $filters = []): bool { - return count($this->getMedia($collectionName)) ? true : false; + return count($this->getMedia($collectionName, $filters)) ? true : false; } /** diff --git a/tests/Feature/InteractsWithMedia/HasMediaTest.php b/tests/Feature/InteractsWithMedia/HasMediaTest.php index 28febfffb..b886e39e2 100644 --- a/tests/Feature/InteractsWithMedia/HasMediaTest.php +++ b/tests/Feature/InteractsWithMedia/HasMediaTest.php @@ -50,4 +50,17 @@ public function it_returns_true_for_a_non_empty_named_collection() $this->assertTrue($this->testModel->hasMedia('images')); $this->assertFalse($this->testModel->hasMedia('downloads')); } + + /** @test */ + public function it_returns_true_for_a_filtered_collection() + { + $this->testModel + ->addMedia($this->getTestJpg()) + ->withCustomProperties(['test' => true]) + ->toMediaCollection(); + + $this->assertTrue($this->testModel->hasMedia('default')); + $this->assertTrue($this->testModel->hasMedia('default', ['test' => true])); + $this->assertFalse($this->testModel->hasMedia('default', ['test' => false])); + } }