php:7.3.4
Laravel Framework 5.7.28
大家好。帮助添加所有关系的数据。
现在,由于某种原因,事实证明仅添加了最后一个关系。
setRelations
的工作方式与此类似。
代码
public static function firstOrCreateModel() {
$cart = Cart::firstOrCreate(self::getWhereQuery());
if ($cart->delivery === 1) {
$cart->setRelation('np_area', $cart->with('npArea')->first());
$cart->setRelation('np_city', $cart->with('npCity')->first());
$cart->setRelation('np_warehouse', $cart->with('npWarehouse')->first());
dump($cart->toArray());
}
return $cart;
}