我自己写了一个Hash实现HashContract,在config里加载了provider,但是测试还是用了原来那个
1.
use Illuminate\Contracts\Hashing\Hasher as HashContract;
class MyHash implements HashContract {
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*/
public function make ($value, array $options = [ ])
{
// TODO: Implement make() method.
return md5($value);
}
2.
use Illuminate\Support\ServiceProvider;
class MyHashServiceProvider extends ServiceProvider {
/**
* Register the service provider.
*
* @return void
*/
public function register ()
{
// TODO: Implement register() method.
$this->app->singleton('hash',function(){
return new MyHash();
});
}
}
3.
config/app
'providers' => [
App\Service\MyHashServiceProvider::class,
/*
4.
dd(\Hash::make(1)); 输出是原来的加密
use Illuminate\Contracts\Hashing\Hasher as HashContract;
class MyHash implements HashContract {
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*/
public function make ($value, array $options = [ ])
{
// TODO: Implement make() method.
return md5($value);
}
2.
use Illuminate\Support\ServiceProvider;
class MyHashServiceProvider extends ServiceProvider {
/**
* Register the service provider.
*
* @return void
*/
public function register ()
{
// TODO: Implement register() method.
$this->app->singleton('hash',function(){
return new MyHash();
});
}
}
3.
config/app
'providers' => [
App\Service\MyHashServiceProvider::class,
/*
4.
dd(\Hash::make(1)); 输出是原来的加密
0 个回复