Skip to content

Commit

Permalink
Merge pull request #1 from mwikala/append-sqid-attribute
Browse files Browse the repository at this point in the history
Append the `sqid` to the Model arrayable attributes.
  • Loading branch information
bensherred authored Dec 3, 2023
2 parents 8b03f4b + 624842e commit a0c92c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Concerns/HasSqids.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

trait HasSqids
{
protected function initializeHasSqids(): void
{
$this->append(['sqid']);
}

public function getSqidAttribute(): ?string
{
return Sqids::forModel(model: $this);
Expand Down
9 changes: 9 additions & 0 deletions tests/Concerns/HasSqidsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@
expect(Customer::keyFromSqid(sqid: $customer->sqid))
->toBe(1);
});

it('appends the sqid to the model array', function (): void {
$customer = CustomerFactory::new()->create();

expect($customer->toArray())
->toHaveKey('sqid')
->and($customer->toArray()['sqid'])
->toBe($customer->sqid);
});

0 comments on commit a0c92c4

Please sign in to comment.