<?php

namespace App\Service;
use App\Models\ContactPerson;
use Log;
use Auth;

class ContactPersonService
{
    public function contactPersonCreateUpdate($request,$user){

        if(isset($request['contact_persons'])){

            foreach ($request['contact_persons'] as $key => $persons) {
                # code...
            
                $data=[
                    'salutation','first_name','last_name','mobile_no','email','work_phone'
                ];
                
                foreach ($data as $key => $value) {
                    if(isset($persons[$value]) && $persons[$value]!=null && $persons[$value]!=''){
                        $obj[$value]=$persons[$value];
                    }
                }
                
               
                $obj['user_id']=$user['id'];
    
                $address=ContactPerson::create($obj);

                $address->update();

               
            }
        }
            return true;
        
    }


}