Example #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);
     }
 }
Example #2
0
 public function planPost()
 {
     $date = new \DateTime(\Input::get('day'));
     $meal = Meal::find(\Input::get('meal-id'));
     $portions = $meal->getPortions();
     foreach ($portions as $portion) {
         $day = new \Excessive\IDF\Models\DayPortion();
         $day->date = $date;
         $day->meal_type_id = $meal->type->id;
         $day->portion_id = $portion->id;
         $day->save();
     }
     return \Redirect::back()->with('success', 'You have assigned a meal to that day');
 }