2014-06-26 14 views

Antwort

12

pivot nur im Rahmen einer Beziehung verfügbar:

// won't work 
$model = Model::first(); 
$model->pivot; // null 

// will work 
$anotherModel = AnotherModel::first(); 
$relatedModel = $anotherModel->relation()->first(); 
$relatedModel->pivot; // Pivot object 

Aber für das, was Sie versuchen, verwenden Sie einfach zusätzliche param im save Methode zu tun :

$product = Product::find($item->id); 
$order->product()->save($product, ['price' => 12.34]); 

Für bestehende Beziehung:

$product = $order->product()->find($productId); 
$product->pivot->price = 12.34; 
$product->pivot->save(); 

// or 
$order->product()->updateExistingPivot($productId, ['price'=>12.34]); 

Und ich schlage vor, Sie verwenden products für diese Art von Beziehung, um es einfacher zu lesen.

0

Sie sollten den Drehpunkt selbst speichern().

$order->pivot->price = '1.234'; 
$order->pivot->save(); 
Verwandte Themen