Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add filter param to hasMedia() #2648

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/HasMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function addMedia($file): FileAdder;
*/
public function copyMedia($file): FileAdder;

public function hasMedia(string $collectionMedia = ''): bool;
public function hasMedia(string $collectionName = ''): bool;

/**
* Get media collection by its collectionName.
Expand Down
4 changes: 2 additions & 2 deletions src/InteractsWithMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/InteractsWithMedia/HasMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}