我是laravel的新手。我想在我的模型中覆盖构造方法,但是,当我尝试在我的模型中使用构造方法时,它返回一个错误说Call to undefined method Illuminate\Database\Query\Builder::construct()
使用__construct
方法的目的是我想动态使用DB表。
问题是什么?怎么可以避免这个错误?
模型
class Custom extends Model
{
protected $guarded = ['id', 'ct'];
const UPDATED_AT = null;
const CREATED_AT = 'ct';
public function __construct(string $tableName = null, array $attributes = []) {
$this->setTable($tableName);
parent::construct($attributes);
}
}
调节器
$custom = new Custom($tableName);
$result = $custom->create($data);
你可能意味着使用parent::__construct($attributes);
而不是parent::construct($attributes);
.There没有construct
方法,就像错误消息所说。