get(); $this->info('Found ' . $videos->count() . ' videos!'); foreach ($videos as $video) { $filename = $video->getFilename(); $this->info('Searching for match from filename: ' . $filename); $tournaments = Model\Tournament::all()->filter( function ($object) use ($filename) { return $object->isMatch($filename); } ); if (!$tournaments->count()) { $this->info('Could not find tournament from filename: ' . $filename); return; } $this->info('Found Tournmament:' . $tournaments->first()->name); $tournament_ids = $tournaments->pluck('id'); $teams = Model\Team::all()->filter( function ($object) use ($filename) { return $object->isMatch($filename); } ); if (!$teams->count()) { $this->info('Could not find teams from filename: ' . $filename); continue; } if ($teams->count() == 1) { $this->info('Could only find 1 team (' . $teams->first()->name . ') from filename: ' . $filename); continue; } $this->info('Found Teams:' . $teams->first()->name, $teams->slice(1, 1)->first()->name); $team_ids = $teams->pluck('name')->toArray(); $matches = $tournaments->first()->matches; foreach ($matches as $match) { if (in_array($match->getHomeTeam()->name, $team_ids)) { if (in_array($match->getAwayTeam()->name, $team_ids)) { $this->info('Found Match for filename: ' . $filename); $match->videos()->save($video); Storage::disk('local')->move( 'youtube/video/' . $video->getFilename(), 'public/matches/' . $video->getFilename() ); continue 2; } } } $this->info('Failed to find Match for filename: ' . $filename); } return Command::SUCCESS; } }