https://github.com/kduma-OSS/LV-eloquent-tokenable
Allows using tokens (HashIDs) instead of id in Laravel Eloquent models.
https://github.com/kduma-OSS/LV-eloquent-tokenable
laravel php
Last synced: about 1 year ago
JSON representation
Allows using tokens (HashIDs) instead of id in Laravel Eloquent models.
- Host: GitHub
- URL: https://github.com/kduma-OSS/LV-eloquent-tokenable
- Owner: kduma-OSS
- License: mit
- Created: 2015-01-31T05:10:49.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-11-11T18:35:45.000Z (over 1 year ago)
- Last Synced: 2024-11-13T13:03:14.816Z (over 1 year ago)
- Topics: laravel, php
- Language: PHP
- Homepage: https://opensource.duma.sh/libraries/eloquent-tokenable
- Size: 11.7 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# L5-eloquent-tokenable
[](https://packagist.org/packages/kduma/eloquent-tokenable)
[](https://packagist.org/packages/kduma/eloquent-tokenable)
[](https://packagist.org/packages/kduma/eloquent-tokenable)
[](https://packagist.org/packages/kduma/eloquent-tokenable)
[](https://insight.sensiolabs.com/projects/76ba87c2-d5c1-4516-af23-3d38f2990145)
[](https://styleci.io/repos/30102978)
Allows using tokens (HashIDs) instead of id in Laravel Eloquent models.
# Setup
Add the package to the require section of your composer.json and run `composer update`
"kduma/eloquent-tokenable": "^1.1"
# Prepare models
In your model add following lines:
use \KDuma\Eloquent\Tokenable;
protected $appends = array('token');
Optionally you can add also:
- `protected $salt = 'SALT';`
A salt for making hashes. Default is table name. This salt is added to your `APP_KEY`.
- `protected $length = 10;`
A salt length. Default is 10.
- `protected $alphabet = 'qwertyuiopasdfghjklzxcvbnm1234567890';`
A hash alphabet. Default is `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`
# Usage
- `$model->token` - Generate tokens
- `Model::whereToken($id)->first()` - Find by token. (`whereToken` is query scope)
# Hashids
A special thanks to creators of [hashids](https://github.com/ivanakimov/hashids.php), a PHP class that this package is based.
# Packagist
View this package on Packagist.org: [kduma/eloquent-tokenable](https://packagist.org/packages/kduma/eloquent-tokenable)