Beispiel #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $days = ['Fri', 'Sat', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu'];
     $strict = $this->option('strict');
     if ($strict && Meal::where('meal_type_id', 2)->count() < count($days)) {
         $this->error('There must be at least ' . count($days) . ' meals to choose from');
         return false;
     }
     $picks = array();
     $meals = Meal::where('meal_type_id', 2)->get();
     $max = count($meals);
     while (count($picks) < count($days)) {
         do {
             $random = rand(0, $max);
             $this->info(count($picks));
             $this->info(count($meals));
         } while (!isset($meals[$random]));
         $pick = $meals[$random];
         unset($meals[$random]);
         $picks[] = $pick;
     }
     foreach ($picks as $index => $pick) {
         $this->info($days[$index] . ': ' . $pick->name);
     }
 }
Beispiel #2
0
 public function createPost()
 {
     $exists = Meal::where('name', \Input::get('meal-name'))->first();
     if ($exists) {
         return \Redirect::back()->with('error', 'That name has already been used');
     }
     $meal = new Meal();
     $meal->name = \Input::get('meal-name');
     $meal->meal_type_id = \Input::get('meal-type');
     $meal->save();
     return \Redirect::back()->with('success', 'You have successfuly created a meal');
 }