elfsundae / laravel-hashid Goto Github PK
View Code? Open in Web Editor NEWObfuscate your data by generating reversible, non-sequential, URL-safe identifiers.
License: MIT License
Obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.
License: MIT License
可以支持中文吗? 对中文生成可逆的
I would like to create a pull request to add these traits for eloquent models. I would change it a bit to use this lib instead of hashid directly, but you get the idea.
I use these two alot and think it would be great to include them to this lib
/**
* Trait HashID
* @package App\Traits
* @property-read string $hash_id
* @mixin Model
*/
trait HashID
{
public function getHashIdAttribute()
{
return static::idToHash($this->getKey());
}
public static function idToHash($id)
{
return static::newHashId()->encode($id);
}
public static function hashToId($code)
{
$ids = static::newHashId()->decode($code);
$id = empty($ids) ? null : $ids[0];
return $id;
}
/**
* @param $code
* @param array $columns
* @return static
*/
public static function findByHash($code, $columns = null)
{
$id = static::hashToId($code);
return static::find($id, $columns);
}
/**
* @param $code
* @param array $columns
* @return static
*/
public static function findOrFailByHash($code, $columns = null)
{
$id = static::hashToId($code);
return static::findOrFail($id, $columns);
}
public static function newHashId()
{
return new Hashids(config('app.key'), 5, 'qwertyuiopasdfghjklzxcvbnm7894561230');
}
}
/**
* Trait HashID
* @package App\Traits
* @mixin \Eloquent
* @mixin HashID
*/
trait HashIDRoutable
{
public function getRouteKeyName()
{
return 'hash_id';
}
public function resolveRouteBinding($value)
{
return (new static)->find(static::hashToId($value));
}
}
class OrderReturn extends Model
{
use HashID;
use HashIDRoutable; // hash id is used instead of id
}
It seems like $this->option('characters') targeting Illuminate\Console\Command::option() can also be of type array; however, ElfSundae\Laravel\Hashid...enerateRandomAlphabet() does only seem to accept string, maybe add an additional type check?
因为我的后台使用laravel nova编写,不清楚是否只修改model即可使用。谢谢!
Considering that PHP 7.x is required since quite some time in Laravel, I think it is safe and sane to drop 5.x support.
This would allow to move on with some other dependencies such as hashids 3.x which requires PHP 7.x
Hi;
I tried to upgrade to Laravel 8 today but noticed your package does not support this in the composer.json
.
Is this something you'd like a PR for or are you happy to update the composer and tag a new release?
Cheers
Shaun
比如('Sbds311',15613,'33')
这种能加密吗?
It is missing because of the reference to illuminate/support ~5.0|~6.0
in src/Console/AlphabetGenerateCommand.php, line 31
This loop uses a function. To avoid the overhead of executing the function n times, you should precalculate it before the loop.
*
* @return mixed
*/
public function handle()
{
for ($i = 0; $i < $this->getTimes(); $i++) {
$this->comment(
$this->generateRandomAlphabet($this->option('characters'))
);
}
}
Posted from SensioLabsInsight
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.