Exemple #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     if (App::environment() === 'production') {
         exit('Do not seed in production environment');
     }
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     // disable foreign key constraints
     DB::table('users')->truncate();
     DB::table('volunteers')->truncate();
     DB::table('doctors')->truncate();
     User::create(['id' => 1, 'name' => 'admin', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 2]);
     User::create(['id' => 2, 'name' => 'volunteer1', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 5]);
     User::create(['id' => 3, 'name' => 'Arun', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 4]);
     User::create(['id' => 4, 'name' => 'Biswas', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 4]);
     User::create(['id' => 5, 'name' => 'Sunil', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 4]);
     User::create(['id' => 6, 'name' => 'volunteer2', 'email' => '*****@*****.**', 'password' => '$2y$10$zJxQkCB6UNr9zzLIgve71ekLMEcOWue/lKuyCtunV559qN2NDV1ra', 'roleId' => 5]);
     Volunteer::create(['userId' => 3, 'firstname' => 'volunteer1', 'lastname' => 'volunteer1', 'contactNumber' => '9717017651', 'isVerified' => true]);
     Volunteer::create(['userId' => 6, 'firstname' => 'volunteer2', 'lastname' => 'volunteer2', 'contactNumber' => '9717017650', 'isVerified' => true]);
     Doctor::create(['userId' => 3, 'firstname' => 'Arun', 'lastname' => 'Jain', 'contactNumber' => '9717017650', 'specialization' => 1, 'location' => 'Delhi', 'isVerified' => true]);
     Doctor::create(['userId' => 4, 'firstname' => 'Biswas', 'lastname' => 'Rao', 'contactNumber' => '9717017651', 'specialization' => 2, 'location' => 'Bangalore', 'isVerified' => true]);
     Doctor::create(['userId' => 5, 'firstname' => 'Sunil', 'lastname' => 'Jain', 'contactNumber' => '9717017651', 'specialization' => 2, 'location' => 'Bangalore', 'isVerified' => true]);
     DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     // enable foreign key constraints
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     // Create a faker, add en_SG providers
     $faker->addProvider(new Faker\Provider\en_SG\Address($faker));
     $faker->addProvider(new Faker\Provider\en_SG\Enhanced($faker));
     $faker->addProvider(new Faker\Provider\en_SG\Person($faker));
     $faker->addProvider(new Faker\Provider\en_SG\PhoneNumber($faker));
     $faker->seed(9876);
     // Calling the same script twice with the same seed produces the same results
     $jobTitles = array('Accountant', 'Artist', 'Artiste', 'Associate Treasury Markets', 'Bank Executive', 'Banker', 'Bus Captain', 'Cashier', 'Chemist', 'Civil Servant', 'Civil Service', 'Cleaner', 'Company Director', 'Compliance Officer', 'Credit Control VP', 'Customer Service', 'Designer', 'Director', 'Doctor', 'Driver', 'Education Officer', 'Electrician', 'Engineer', 'Entrepreneur', 'Events Industry', 'Executive', 'Finance Consultant', 'Financial Service Consultant', 'Freelancer', 'Hawker', 'Homemaker', 'Hairdresser', 'HR Manager', 'Human Resource Executive', 'Insurance Agent', 'Jobless', 'Junior Executive', 'Manager', 'Music director', 'Nurse', 'Optometrist', 'Penetration Tester', 'Pilot', 'Police', 'Project Engineer', 'Project Manager', 'Self-employed', 'Soldier', 'Surgeon', 'Taxi Driver', 'Teacher', 'Tuition Teacher', 'Unemployed');
     // Insert 10 dummy records
     foreach (range(1, 10) as $index) {
         $gender = $faker->randomElement(['male', 'female']);
         $dob = $faker->dateTimeBetween('-50 years', '-16 years');
         $fullName = explode("|", $faker->unique()->nameWithSalutation($gender));
         // Extract full name without salutation ("Full Name|Salutation" to array)
         $fullName = $fullName[0];
         $emailName = strtolower(preg_replace('/\\s+/', '', $fullName));
         // Remove whitespaces in full name, convert to lowercase
         strlen($emailName) > 8 ? $emailName = substr($emailName, 0, 8) : null;
         // Extract only 8 characters from full name
         $email = $emailName . substr($dob->format('Y'), -2) . '@' . $faker->localFreeEmailDomain;
         // 8 characters from full name + last 2 digit from birth year + email domain
         $approval = $faker->optional(0.9, 'rejected')->randomElement(['pending', 'approved']);
         // 10% chance of rejected
         $dob->diff(Carbon::now())->y > 21 ? $job = $faker->optional(0.9, 'Student')->randomElement($jobTitles) : ($job = 'Student');
         // Age 21 or younger are all students
         Volunteer::create(['nric' => $faker->unique()->nric, 'name' => $fullName, 'email' => $email, 'password' => 'qwerty123', 'gender' => ucwords($gender[0]), 'date_of_birth' => $dob, 'contact_no' => preg_replace('/-/', '', $faker->mobile), 'occupation' => $job, 'has_car' => $faker->boolean(30), 'minutes_volunteered' => $approval == 'rejected' ? 0 : $faker->optional(0.6, 0)->numberBetween(1, 9) * (60 * $faker->numberBetween(1, 3)), 'area_of_preference_1' => 'Befriend senior citizens', 'area_of_preference_2' => 'Lead games/exercises', 'image_nric_front' => 'image/image_nric_front.jpg', 'image_nric_back' => 'image/image_nric_back.jpg', 'is_approved' => $approval, 'rank_id' => 4]);
     }
 }
 /**
  * Store a new volunteer.
  * Responds to requests to POST /volunteers
  *
  * @param  \App\Http\Requests\CreateVolunteerRequest  $request
  * @return Response
  */
 public function store(CreateVolunteerRequest $request)
 {
     $randomString = Str::random();
     $volunteer = Volunteer::create(['name' => $request->get('name'), 'email' => $request->get('email'), 'password' => $randomString, 'gender' => $request->get('gender'), 'date_of_birth' => $request->get('date_of_birth'), 'contact_no' => $request->get('contact_no'), 'occupation' => $request->get('occupation'), 'has_car' => $request->get('car'), 'area_of_preference_1' => $request->get('area_of_preference_1'), 'area_of_preference_2' => $request->get('area_of_preference_2'), 'is_approved' => 'approved', 'rank_id' => Rank::lowest()->first()->rank_id]);
     $email = $volunteer->email;
     Mail::send('emails.welcome_volunteer', compact('volunteer', 'randomString'), function ($message) use($email) {
         $message->subject('Your CareGuide Volunteer account has been registered.');
         $message->bcc($email);
     });
     return redirect('volunteers')->with('success', 'Volunteers is added successfully!');
 }
 /**
  * Handles registration process of new volunteer.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return  JSON  array of status
  */
 public function addUserAccount(Request $request)
 {
     Volunteer::create(['nric' => $request->get('nric'), 'name' => $request->get('name'), 'email' => $request->get('email'), 'password' => $request->get('password'), 'gender' => $request->get('gender'), 'date_of_birth' => $request->get('dob'), 'contact_no' => $request->get('phone'), 'occupation' => $request->get('occupation'), 'has_car' => $request->get('haveCar'), 'minutes_volunteered' => '0', 'area_of_preference_1' => $request->get('preferences1'), 'area_of_preference_2' => $request->get('preferences2'), 'image_nric_front' => $request->get('frontIC'), 'image_nric_back' => $request->get('backIC'), 'rank_id' => Rank::where('min', 0)->first()->rank_id]);
     $volunteer = Volunteer::where('email', $request->get('email'))->first();
     $mailingList = Staff::where('is_admin', 'TRUE')->lists('email')->toArray();
     if ($volunteer == null) {
         $status = ["error"];
         return response()->json(compact('status'));
     } else {
         Mail::send('emails.volunteer_registration', compact('volunteer'), function ($message) use($mailingList) {
             $message->subject('New Volunteer Registration');
             $message->bcc($mailingList);
         });
         $status = ["Created successfully"];
         return response()->json(compact('status'));
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(VolunteerFormRequest $request)
 {
     $data = $request->all();
     foreach ($data as $i => $item) {
         if (is_array($item)) {
             $data[$i] = serialize($item);
         }
     }
     Volunteer::create($data);
     Mail::send('emailtemplates.volunteerform', $data, function ($message) {
         $volunteer_email = AdminEmail::where('role', '=', 'volunteer_form')->first();
         //$volunteer_email = '*****@*****.**';
         $message->from('*****@*****.**');
         $message->to($volunteer_email->email)->subject('RBE Volunteer Form');
     });
     return redirect('/volunteer')->with('message', 'Thank you for your interest in volunteering!');
 }