我需要扩展 ModelTable 类只添加一次 follow 方法,而不是在每个类中
public function addOrUpdate($data, $options=[]) {
if ($this->existe($data)) {
$obj = $this->findById($data['id'])->first();
$obj = $this->patchEntity($obj, $data,$options);
}else{
$obj = $this->newEntity($data,$options);
}
return $this->save($obj);
}
您可以创建一个扩展 Table 类的 CustomTable 类。将您的函数放在 CustomTable 类中。然后您可以创建扩展 CustomTable 类的每个模型表类。
class CustomTable extends Table {
public function addOrUpdate($data, $options = [])
{
...
}
}
class ModelTable extends CustomTable {
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句