belongsToMany(User::class); } public static function createnew($contact) { $id = $contact->id; unset($contact->id); $contact = Paramedics::firstOrCreate(['id' => $id], (array)$contact); return $contact; } public static function updateone($post, $user, $id) { $contact = Contact::find($id); foreach($post as $k => $p) { if(isset($contact->{$k}) && $contact->{$k} != '' && $k != 'tags') unset($post[$k]); } $divisions = is_array($contact->divisions)?$contact->divisions:[]; $users = is_array($contact->users)?$contact->users:[]; $tags = is_array($contact->tags)?$contact->tags:[]; $divisions[] = $user->division_id; $users[] = $user->id; $tags = array_merge($tags, explode(',', $post['tags'])); $post['divisions'] = array_unique($divisions); $post['users'] = array_unique($users); $post['tags'] = array_unique($tags); $contact->update($post); return $contact; } public static function updatebyuser($post, $id) { $contact = Contact::find($id); foreach($post as $k => $p) { if($p == '') unset($post[$k]); } $tags = is_array($contact['tags'])?$contact['tags']:[]; if(isset($post['tags'])) { $tags = array_merge($tags, explode(',', $post['tags'])); } unset($post['tags']); $post['tags'] = array_unique($tags); $contact->update($post); return $contact; } }