Exemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $selected = new \stdClass();
     $protein = Portion::whereHas('type', function ($q) {
         $q->where('name', 'Protein')->where('include_random', true);
     })->get();
     $random = rand(0, count($protein) - 1);
     $selected->protein = $protein[$random];
     $starch = Portion::whereHas('type', function ($q) {
         $q->where('name', 'Starch')->where('include_random', true);
     })->get();
     $random = rand(0, count($starch) - 1);
     $selected->starch = $starch[$random];
     $veg = Portion::whereHas('type', function ($q) {
         $q->where('name', 'Vegetable')->where('include_random', true);
     })->get();
     $random = rand(0, count($veg) - 1);
     $selected->veg = $veg[$random];
     try {
         $this->line('Protein: ' . $selected->protein->name);
         $this->line('Starch: ' . $selected->starch->name);
         $this->line('Vegatable: ' . $selected->veg->name);
     } catch (\Exception $ex) {
         $this->error($ex->getMessage());
     }
 }
Exemplo n.º 2
0
 public function getRandom()
 {
     $type = $this->portionType->name;
     $pick = \Excessive\IDF\Models\Portion::whereHas('types', function ($q) use($type) {
         $q->where('name', $type);
     })->where('random', true)->get();
     $rand = rand(0, $pick->count() - 1);
     return $pick[$rand];
 }