Fil*_*ski 106
就在这里.你只需要定义这样的新特征:
trait MySoftDeletes
{
use SoftDeletes {
SoftDeletes::saveWithHistory as parentSaveWithHistory;
}
public function saveWithHistory() {
$this->parentSaveWithHistory();
//your implementation
}
}
Run Code Online (Sandbox Code Playgroud)
我有不同的方法。ParentSaveWithHistory在这个特性中仍然是适用的方法,所以至少应该定义为私有的。
trait MySoftDeletes
{
use SoftDeletes {
saveWithHistory as private parentSaveWithHistory;
}
public function saveWithHistory()
{
$this->parentSaveWithHistory();
}
}
Run Code Online (Sandbox Code Playgroud)
还要考虑特征中的“覆盖”方法:
use SoftDeletes, MySoftDeletes {
MySoftDeletes::saveWithHistory insteadof SoftDeletes;
}
Run Code Online (Sandbox Code Playgroud)
此代码使用saveWithHistoryfrom方法MySoftDeletes,即使它存在于SoftDeletes.
| 归档时间: |
|
| 查看次数: |
14859 次 |
| 最近记录: |