gpt4 book ai didi

php - 添加静态函数boot()后的laravel模型未定义索引

转载 作者:行者123 更新时间:2023-12-05 00:45:30 25 4
gpt4 key购买 nike

我将此语法添加到模型中:

public static function boot()
{
if(Auth::user()){
parent::boot();
static::saving(function ($model) {
$model->school_id = Auth::user()->school_id;
});

static::addGlobalScope('school_id', function (Builder $builder) {
$builder->where('school_id', Auth::user()->school_id);
});
}
}

在网络上运行良好,但在 API 中不行,错误:

ErrorException: Undefined index: App\SmStudent in file/home/simsmar/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.phpon line 241

.

Laravel 框架 5.8.37

当我删除“if(Auth::user())”并且只删除“公共(public)静态函数”时boot()"还是一样的错误

最佳答案

终于找到了解决办法

只要给

父::boot();

在静态函数的第一行

关于php - 添加静态函数boot()后的laravel模型未定义索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63423627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com