Esempio n. 1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(UserRepository $repository, Flash $flash)
 {
     $user = $repository->findUserByEmail($this->data['email']);
     if ($user) {
         $flash->error('Email already exists.');
         return null;
     }
     return $repository->registerUser($this->data);
 }
Esempio n. 2
0
 public function import($filename, UserRepository $userRepository)
 {
     $file = "{$filename}.csv";
     $csv = array_map('str_getcsv', file(storage_path($file)));
     foreach ($csv as $c) {
         // first name, last name and email cannot be empty
         if (empty($c[0]) || empty($c[1]) || empty($c[3])) {
             continue;
         }
         $firstname = trim($c[0]);
         $lastname = trim($c[1]);
         if ($filename == 'Agents') {
             $name = explode(' ', $lastname);
             $num = count($name);
             if ($num > 1) {
                 $lastname = trim($name[$num - 1]);
             }
         }
         $phone = $c[2] ? trim($c[2]) : '';
         $email = trim($c[3]);
         $address = $c[4] ? trim($c[4]) : '';
         $city = $c[5] ? trim($c[5]) : '';
         $state = $c[6] ? trim($c[6]) : '';
         $zipcode = $c[7] ? trim($c[7]) : '';
         $country_id = empty($c[8]) ? 1 : $c[8];
         $agency = $filename == 'Agents' ? trim($c[9]) : '';
         $data = compact('firstname', 'lastname', 'phone', 'email', 'address', 'city', 'state', 'zipcode', 'country_id', 'agency');
         $user = $userRepository->findUserByEmail($data['email']);
         if (empty($user)) {
             $userRepository->registerUser($data);
         }
     }
     echo 'Done';
 }