I have this pivot table containing
imei status item_id
and here is my code
$update = Item::find($item_id)->workArea()->wherePivot('imei', '=', 3)->first();
$update->pivot->status = 'Sold';
$update->pivot->save();
Before the function execute:
IMEI STATUS ITEM-ID
3 Available 3
5 Available 3
Result:
IMEI STATUS ITEM-ID
3 Sold 3
3 Sold 3
What I need:
IMEI STATUS ITEM-ID
3 Sold 3
5 Available 3
Here's my relationship
public function workArea()
{
return $this->belongsToMany('WorkArea','item_work-area','item_id','work-area_id')->withPivot('imei','status');
}
here are the past conversation with other artisan http://laravel.io/forum/07-08-2014-proper-chaining-for-my-pivot-table-to-execute-pivot-update
This is in bugged with the current version 4.1
What I do is make a raw query instead of eloquent ORM,
DB::table('item_work-area')
->where('imei', 11)
->update(array('status' => 'Sold'));
Hope this help for those who need to update their pivot table using added column as reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With