想象一下我有以下模型:
class Link extends Model
{
protected $fillable = ['path', 'secret'];
public function setSecretAttribute($value)
{
$this->attributes['secret'] = sha1($value);
}
}
Run Code Online (Sandbox Code Playgroud)
以及以下代码:
$link = Link::firstOrCreate(['path' => $someValue, 'secret' => $anotherValue]);
Run Code Online (Sandbox Code Playgroud)
我的代码是否有问题,或者“firstOrCreate”在检查注册表是否已存在时忽略变异器?如果它忽略,我只需将 sha1 加密添加到“anotherValue”即可获得我期望的行为。但我的问题是,这不是多余的吗?
laravel ×1