/** * 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); }
/** * Execute the job. * * @return void */ public function handle(UserRepository $repository, Flash $flash) { $user = $repository->findUser($this->id); if ($user->email != $this->data['email']) { if ($repository->findUserByEmail($this->data['email'])) { $flash->error('Email already exists.'); return null; } } return $repository->updateUser($this->id, $this->data); }
/** * Booking form * * @param int $tourId * @return Response */ public function create($tourId, Request $request, UserRepository $userRepository, TourRepository $tourRepository, CountryRepository $countryRepository) { $this->validate($request, ['email' => 'required|email|max:200']); $email = $request->input('email'); $user = $userRepository->findUserByEmail($email); $user = $user ? $user : new User(); $tour = $tourRepository->findTour($tourId); $countries = $countryRepository->getAllCountries(); $pageTitle = 'Book a Tour'; return view('bookings.create', compact('pageTitle', 'email', 'user', 'tour', 'countries')); }
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'; }