/**
  * Creates a new entry, puts the id into the session and
  * redirects back to the index page.
  */
 public function store()
 {
     if (Entry::canCreateOrEdit() === false) {
         return Redirect::route('entry.index')->withMessage("Sorry, the competition has now started and new entries cannot be created.");
     }
     $input = Input::all();
     $validator = Validator::make($input, Entry::$entry_rules);
     if ($validator->fails()) {
         return Redirect::route('entry.create')->withInput()->withErrors($validator);
     }
     DB::beginTransaction();
     $entry = new Entry();
     $entry->email = $input['email'];
     $entry->secret = Hash::make($input['secret']);
     $entry->confirmation = uniqid('', true);
     $entry->first_name = $input['first_name'];
     $entry->last_name = $input['last_name'];
     $entry->peer_group = $input['peer_group'];
     $entry->save();
     $matches = Match::all();
     foreach ($matches as $match) {
         $match_prediction = new MatchPrediction();
         $match_prediction->team_a = $match->team_a;
         $match_prediction->team_b = $match->team_b;
         $match_prediction->pool = $match->pool;
         $match_prediction->match_date = $match->match_date;
         $entry->matchPredictions()->save($match_prediction);
     }
     DB::commit();
     $this->sendConfirmationEmail($entry);
     $this->putEntryIdIntoSession($entry->id);
     return View::make('entry.edit')->with('entry', $entry);
 }
 /**
  * Updates the matches results.
  */
 public function updateMatches()
 {
     $matches = Match::all();
     foreach ($matches as $match) {
         $field = "match_{$match->id}";
         if (Input::has($field)) {
             $match->result = Input::get($field);
         } else {
             $match->result = null;
         }
         $match->save();
     }
     return Redirect::route('admin.index')->withInfo('Match results saved.');
 }
 public function results()
 {
     $matches = Match::all();
     $admin_entry = Entry::where('email', 'admin')->first();
     return View::make('results')->with('matches', $matches)->with('entry', $admin_entry);
 }