2017-04-24 55 views
1

更新到最新的稳定版本后,我在更新透视数据时遇到了一个奇怪的行为。如何更新数据透视表数据

我有一个像这样的顺序透视表更新的产品数量ajax的处理程序:

foreach (input('quantity') as $id => $quantity) { 
    $order->products()->updateExistingPivot($id, ['quantity' => $quantity]); 
} 

这成功地更新数据透视表中的数据和everyting看起来不错。

现在我刷新模式,使数据将高达最新:

$order = $order->fresh(); 

现在的奇怪的一部分。谁能给我解释一下,为什么这个返回旧支点值:

$order->products->first()->pivot->quantity; 

而这个返回更新后的值:

$order->products()->first()->pivot->quantity; 

此前的第一个返回新太超值了。

回答

1

的解决方案是使用fresh()函数关系名称:

$order = $order->fresh(['products']); 

不知道为什么它工作之前虽然