예제 #1
0
 /**
  * generate test date applications and users
  * @param int
  * @return mixed
  */
 public function generateTestDate($numberOfDate)
 {
     // process time start
     $pStartTime = microtime(true);
     // faker
     $faker = Factory::create();
     // gender random array
     $genderArr = ['male', 'female'];
     for ($i = 0; $i < $numberOfDate; $i++) {
         // fake user data
         $fakeUserData = ['nickname' => $faker->userName, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'real_name' => $faker->firstName, 'sex' => $this->genderArr[rand(0, 1)], 'year' => $faker->year, 'month' => $faker->month, 'date' => $faker->dayOfMonth, 'phone_number' => $faker->phoneNumber, 'confirmed' => 1, 'remember_token' => str_random(10)];
         // create faker user
         $fakeUser = User::create($fakeUserData);
         // time range
         $timeRange = array_rand($this->timeArr, 2);
         // start time
         $startTime = $this->timeArr[$timeRange[1]];
         // end time
         $endTime = $this->timeArr[$timeRange[0]];
         // swap time range if not reasonable
         if ($startTime > $endTime && $startTime != 0 && $endTime != 0) {
             list($startTime, $endTime) = array($endTime, $startTime);
         }
         // fake date applicatoin
         $fakeDateAppData = ['user_id' => $fakeUser->id, 'city' => $this->cityArr[array_rand($this->cityArr, 1)], 'start_time' => $startTime, 'end_time' => $endTime, 'vegetarian_type' => $this->vegetarianTypeArr[array_rand($this->vegetarianTypeArr, 1)], 'meal_type' => $this->mealTypeArr[array_rand($this->mealTypeArr, 1)], 'sex_constraint' => $this->genderArr[array_rand($this->genderArr, 1)]];
         // create fake date applicatoin
         $fakeDateApp = DateApplication::create($fakeDateAppData);
     }
     $pTime = microtime(true) - $pStartTime;
     echo 'process time is ' . $pTime;
 }
예제 #2
0
 /**
  * post apply form
  *
  * @param Request $request
  * @return Response
  */
 public function postApplyForDate(Request $request)
 {
     // validate input
     $this->validate($request, ['city' => 'required', 'start_time' => 'required|integer', 'end_time' => 'required|integer', 'vegetarian_type' => 'required|in:是,否,我都可以唷', 'meal_type' => 'required|in:中餐,西餐,我都可以唷'], ['city.required' => '用餐城市不可以空白唷', 'start_time.required' => '用餐開始時間不可以空白唷', 'end_time.required' => '用餐結束時間不可以空白唷']);
     // get input array
     $inputAll = $request->all();
     // append user id input input array
     $inputAll['user_id'] = auth()->user()->id;
     // create date application
     $dateApplication = DateApplication::create($inputAll);
     // show application success page
     return redirect('home');
 }