Example #1
0
 protected function __findCast($cast)
 {
     $cast = Cast::where('code', '=', $cast)->first();
     return Mate::where('cast_id', '=', $cast->id)->where('room_id', '=', $this->room->id)->where('is_alive', '=', 1);
 }
Example #2
0
 public function shuffleCast()
 {
     $mates = $this->mates->all();
     $castArray = $this->__getAllSpecialCastAsArray();
     $peopleNumber = $this->mates->count() - count($castArray);
     $castArray = array_merge($castArray, $this->__sameArray('people', $peopleNumber));
     if (empty($castArray)) {
         return null;
     }
     $catchData = range(0, count($castArray) - 1);
     shuffle($catchData);
     $newMate = [];
     foreach ($mates as $mate) {
         $val = array_pop($catchData);
         $cast = Cast::where('code', '=', $castArray[$val])->first();
         $mate->cast_id = $cast->id;
         $mate->save();
         $newMate[] = $mate;
     }
 }