追加 HasManyThrough 对象
Append for HasManyThrough objects
我的主题 class 具有 HasManyThrough
关系的用户。
return $subject->users; //returns an array with ids and names from the database
现在我想添加一个动态 appends
变量,该变量不应包含在 user
class 中,因为并非所有地方都需要它。
那么有没有办法为整个 HasManyThrough
对象设置这个 appends
值?
A HasManyThrough
也是一个 Collection
所以可以 运行 用 map:
$subject->users->map(function(User $user) {
$user->setAppends(['foo', 'bar']);
return $user;
});
我的主题 class 具有 HasManyThrough
关系的用户。
return $subject->users; //returns an array with ids and names from the database
现在我想添加一个动态 appends
变量,该变量不应包含在 user
class 中,因为并非所有地方都需要它。
那么有没有办法为整个 HasManyThrough
对象设置这个 appends
值?
A HasManyThrough
也是一个 Collection
所以可以 运行 用 map:
$subject->users->map(function(User $user) {
$user->setAppends(['foo', 'bar']);
return $user;
});