public static function index() { self::check_logged_in(); $drafts = Draft::all(); foreach ($drafts as $draft) { $kayttajaid = $draft->id; } $kayttaja = Kayttaja::find($kayttajaid); foreach ($drafts as $draft) { $hero = $draft->hero1; $yhteys = new Yhteys(array('hero_id' => $hero, 'draft_id' => $draft->id)); $testi = Yhteys::find($hero, $draft->id); if ($testi == null) { $yhteys->save(); } $hero = $draft->hero2; $yhteys = new Yhteys(array('hero_id' => $hero, 'draft_id' => $draft->id)); $testi = Yhteys::find($hero, $draft->id); if ($testi == null) { $yhteys->save(); } $hero = $draft->hero3; $yhteys = new Yhteys(array('hero_id' => $hero, 'draft_id' => $draft->id)); $testi = Yhteys::find($hero, $draft->id); if ($testi == null) { $yhteys->save(); } $hero = $draft->hero4; $yhteys = new Yhteys(array('hero_id' => $hero, 'draft_id' => $draft->id)); $testi = Yhteys::find($hero, $draft->id); if ($testi == null) { $yhteys->save(); } $hero = $draft->hero5; $yhteys = new Yhteys(array('hero_id' => $hero, 'draft_id' => $draft->id)); $testi = Yhteys::find($hero, $draft->id); if ($testi == null) { $yhteys->save(); } } View::make('drafts/index.html', array('drafts' => $drafts, 'kayttajat' => $kayttaja)); }