我可以将属性从表单传递到闭包吗?这些属性不会包含在数据库中。目前,在模型中,我只能从迁移文件中获取属性(或从可填充数组中获取值)。
我的代码:
protected static function booted()
{
parent::boot();
static::addGlobalScope(new UserAccessScope);
static::creating(function ($model){
dd($model);
});
}发布于 2021-07-08 11:47:03
Yes可以使用use关键字将属性传递给闭包。例如,如下所示:
protected static function booted()
{
parent::boot();
$test = "This is a test";
static::addGlobalScope(new UserAccessScope);
static::creating(function ($model) use ($test){
echo $test;
dd($model);
});
}发布于 2021-07-08 17:39:15
使用request() helper -但这不是最佳实践。
protected static function booted()
{
parent::boot();
static::addGlobalScope(new UserAccessScope);
static::creating(function ($model) use ($test){
$data = request()->input();
dd($data);
});
}https://stackoverflow.com/questions/68285359
复制相似问题