嗨,我用InfyOm ()。我希望在添加新记录时将随机字符串设置为变量键,但我不知道如何做到这一点。
键控制器
public function store(CreatekeysRequest $request)
{
$input = $request->all();
$keys = $this->keysRepository->create($input);
Flash::success('Added');
return redirect(route('keys.index'));
}我用mutator在键模型上生成字符串,但是当我编辑记录时,键总是被更改。
Keys模型
public function setDomainAttribute($value) {
$this->attributes['domain'] = $value;
$key = $this->attributes['key'] = Str::random(16);
Flash::success("Key generated for {$value}<br><b>{$key}");
} 发布于 2020-05-29 09:57:59
我不熟悉InfyOm,但我相信您可以使用标准的雄辩事件,如下所示:
<?php
// models/Key.php
class Key
{
public static function boot()
{
parent::boot();
self::creating(function($model) {
$model->key = Str::random(16);
});
}
}当您创建新的密钥模型时,上面的代码将设置key属性。
https://stackoverflow.com/questions/62082890
复制相似问题