Skip to content

Commit

Permalink
Merge pull request #88 from GeoSot/gs/add-metable-interface
Browse files Browse the repository at this point in the history
Add an optional `Metable` interface
  • Loading branch information
frasmage committed Oct 22, 2022
2 parents 03978bc + 7a4803a commit f576ece
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ php artisan migrate

5. Add the `Plank\Metable\Metable` trait to any eloquent model class that you want to be able to attach metadata to.

_Note: If need a more generic way to reference different Metable Model classes, you can optionally apply the `Plank\Metable\MetableInterface` to your models._

```php
<?php
Expand Down
51 changes: 51 additions & 0 deletions src/MetableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Plank\Metable;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Collection;
use Plank\Metable\Meta;

/**
* @method static Builder whereHasMeta($key): void
* @method static Builder whereDoesntHaveMeta($key)
* @method static Builder whereHasMetaKeys(array $keys)
* @method static Builder whereMeta(string $key, $operator, $value = null)
* @method static Builder whereMetaNumeric(string $key, string $operator, $value)
* @method static Builder whereMetaIn(string $key, array $values)
* @method static Builder orderByMeta(string $key, string $direction = 'asc', $strict = false)
* @method static Builder orderByMetaNumeric(string $key, string $direction = 'asc', $strict = false)
*/
interface MetableInterface
{
public function meta(): MorphMany;

public function setMeta(string $key, mixed $value): void;

public function setManyMeta(array $metaDictionary): void;

public function syncMeta(iterable $array): void;

/**
* @param string $key
* @param mixed $default
* @return mixed
*/
public function getMeta(string $key, mixed $default = null);

/**
* @return Collection<array-key, mixed>
*/
public function getAllMeta(): Collection;

public function hasMeta(string $key): bool;

public function removeMeta(string $key): void;

public function removeManyMeta(array $keys): void;

public function purgeMeta(): void;

public function getMetaRecord(string $key): ?Meta;
}

0 comments on commit f576ece

Please sign in to comment.