/** * * @param ImportHelper $import * * Imports a file from csv and returns a collection * * Reformats a phone number * @param PhoneFormater $phone */ public function readElements(ImportHelper $import, PhoneFormater $phone) { $recruits = $import->readElements(); Recruits::truncate(); foreach ($recruits as $recruit) { Recruits::create(['first_name' => ucwords($recruit->FirstName), 'last_name' => ucwords($recruit->LastName), 'phone' => $phone->format($recruit->Phone1), 'address' => $recruit->Address1, 'city' => $recruit->City, 'zip_code' => $recruit->Zip, 'email' => $recruit->Email, 'status' => $recruit->ContactType, 'assigned_to' => Auth::user()->id, 'source' => $recruit->LeadSource]); } }
public function import() { $import = new ImportHelper(storage_path() . '/c21/recruit_scrub.csv'); $recruits = $import->readElements(); foreach ($recruits as $recruit) { Recruits::updateOrCreate(['email' => $recruit->EMail], ['mls_id' => $recruit->AgentID, 'first_name' => ucwords($recruit->FirstName), 'last_name' => ucwords($recruit->LastName), 'phone_1' => $this->phone->format($recruit->Phone1), 'phone_1_type' => $recruit->Phone1Type, 'address' => $recruit->Address, 'city' => $recruit->City, 'zip_code' => $recruit->Zip, 'email' => $recruit->EMail, 'user_id' => 1, 'experience_level' => 'Experienced Agent']); } }
/** * Execute the command. * * @return void */ public function handle(Lead $leadrouter) { set_time_limit(400); $import = new ImportHelper($this->file); $phone = new PhoneFormater(); $leads = $import->readElements(); foreach ($leads as $lead) { $leadrouter->updateOrCreate(['id' => $lead->id], ['id' => $lead->id, 'first_name' => ucwords($lead->first_name), 'last_name' => ucwords($lead->last_name), 'phone_1' => $phone->format($lead->phone1), 'phone_2' => $phone->format($lead->phone2), 'listing_address' => $lead->listing_address, 'listing_city' => $lead->listing_city, 'listing_zipcode' => $lead->listing_area_name, 'listing_price' => $lead->listing_price, 'email' => $lead->email, 'status' => $lead->status, 'is_scrubbed' => 0, 'agent_crest_id' => $lead->agent_legacy_id, 'source_name' => $lead->current_source, 'created_at' => Carbon::parse($lead->date_entered), 'updated_at' => Carbon::parse($lead->last_update_date_by_agent)]); } event(new LeadFileWasAdded(Auth::user()->id)); }