laravel - Laravel eloquent - 合并父级 $appends
问题描述
假设我有两个模型,Veichle
并且Car
.
Veichle extends Model {
$appends = ['append_1', 'append_2'];
}
和
Car extends Veichle {
$appends = ['append_3', 'append_4'];
}
append_1
如果我有 Car 对象,我该如何使用?这样 Car 类只是覆盖了父 $appends,我没有找到任何方法来合并它
解决方案
您可以使用该append
方法在构造函数中执行此操作,因为它将提供的属性附加到现有属性:
Car extends Vehicle
{
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->append(['append_3', 'append_4']);
}
}
推荐阅读
- python-3.x - 散景 openStreetMap 磁贴在所有浏览器中不可见
- datafeed - RSA Archer 中的 Archer 到 Archer 数据馈送
- android - 安卓视频镜像效果
- azure - VSTS Azure App Service Deploy 发布任务不更新文件
- c++ - vcxproj 项目属性中未显示的附加包含路径
- r - OSRM:为什么路线 A -> B 的行程时间是路线行程时间 B -> A 的 2 倍?
- machine-learning - Classification based on likelihood toward maximum or minimum of survey score
- prolog - Prolog 中的可选绑定
- bitbucket - 无法从 Bitbucket 克隆
- r - 格式反应元素的日期闪亮