php - Laravel save or update many to many relationship with additional column -


i have many many relationship set in laravel want save user settings. setting can set many users , user can have many settings.

i have additional field named "value" in pivot table want save value set user.

well, want create new entry when there no value particular user , setting. if there value should updated.

this i've tried:

$setting = setting::find(1); auth::user()->settings()->save($setting,array('value' => 15)); 

as change value else automatically creates new entry. i'd updated. how can achieve this?

use updateorcreate method.

$setting = setting::find(1); auth::user()->settings()->updateorcreate($setting,array('value' => 15)); 

method documentation


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -