php - How to use sync() with additional pivot fields [Laravel 5] -


this question has answer here:

here code:

public function updategroupintodatabase(){      $group_id = 6;     $group = group::find($group_id);     $group -> name = input::get('groups');     $projectsids = input::get('projects');      $userids = array_merge(input::get('clients'),input::get('workers'));     array_push($userids, auth::id());     $adminid = auth::id();     if($group -> save()){     foreach($userids $userid){         $name = user::find($userid);         $group -> projects() -> sync($projectsids,array('admin_id' => $adminid, 'user_id' => $userid,'user_name' => $name -> name));      } 

when execute this:

id  project_id  group_id admin_id user_id  user_name 1   4           6        0        0 

but should each user_id create new record... when use attach method works find when use sync create 1 record additional pivot fields filds 0. solution this?

when using sync pivot data:

$group->projects()->sync( array(      1 => array( 'admin_id' => $adminid, 'user_id' => $userid ),     2 => array( 'admin_id' => $adminid, 'user_id' => $userid ),     ... )); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -