Skip to content

Commit

Permalink
feat: move inIds functionality to base collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed May 29, 2024
1 parent 9cb2377 commit b768290
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Abstracts/Collections/EloquentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
namespace Apiato\Core\Abstracts\Collections;

use Illuminate\Database\Eloquent\Collection;
use Vinkla\Hashids\Facades\Hashids;

abstract class EloquentCollection extends Collection
{

/**
* Check if the given hashed id exists in the collection
*/
public function containsHashedId(string $hashedId, string $key = 'id'): bool
{
return $this->contains($key, Hashids::decode($hashedId)[0]);
}
}
2 changes: 1 addition & 1 deletion src/Traits/TestTraits/PhpUnit/TestAssertionHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function assertModelCastsIsEmpty(Model $model, array ...$extraDefaultF
*
* @example $this->inIds($hashedId, $collectionOfModels);
*/
#[Deprecated(reason: 'Use inIds() helper function instead.')]
#[Deprecated(reason: 'Wrong method location and bad design. Use the "containsHashedId" method from the EloquentCollection instead.')]
protected function inIds(string $hashedId, Collection|array $ids): bool
{
if ($ids instanceof Collection) {
Expand Down

0 comments on commit b768290

Please sign in to comment.