Skip to content

Commit

Permalink
Add findByHash method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvaliolahi committed Nov 3, 2021
1 parent d2a294c commit baac388
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ return [
'ids',
]
];
```

## Manual find

```php
$post = Post::findByHash('vm');
```
7 changes: 7 additions & 0 deletions src/Traits/SmartHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ function getHashIdAttribute()
{
return (new Hashids())->encode($this->id);
}

public static function findByHash($hashId)
{
$id = (new Hashids())->decode($hashId)[0];

return static::find($id);
}
}

0 comments on commit baac388

Please sign in to comment.