public function redirect() { //ShortModel::createShort(Request::get('code')); $urlRow = ShortModel::getUrlFromDb(Request::get('code')); if (!empty($urlRow)) { Redirect::out($urlRow->long_url); } else { Redirect::to('error'); } //Redirect::to('short/index'); }
public static function shortCodeToUrl($code, $increment = true) { if (empty($code)) { throw new Exception("No short code was supplied."); } if (ShortModel::validateShortCode($code) == false) { throw new Exception("Short code does not have a valid format."); } $urlRow = ShortModel::getUrlFromDb($code); if (empty($urlRow)) { throw new Exception("Short code does not appear to exist."); } if ($increment == true) { ShortModel::incrementCounter($urlRow["id"]); } return $urlRow["long_url"]; }