Browse Source

added redirect::back method.

Taylor Otwell 12 years ago
parent
commit
55669ee0ae
2 changed files with 21 additions and 0 deletions
  1. 11 0
      laravel/redirect.php
  2. 10 0
      laravel/request.php

+ 11 - 0
laravel/redirect.php

@@ -14,6 +14,17 @@ class Redirect extends Response {
 		return static::to(URL::home($https), $status);
 	}
 
+	/**
+	 * Create a redirect response to the HTTP referrer.
+	 *
+	 * @param  int       $status
+	 * @return Redirect
+	 */
+	public static function back($status = 302)
+	{
+		return static::to(Request::referrer(), $status);
+	}
+
 	/**
 	 * Create a redirect response.
 	 *

+ 10 - 0
laravel/request.php

@@ -131,6 +131,16 @@ class Request {
 		return strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
 	}
 
+	/**
+	 * Get the HTTP referrer for the request.
+	 *
+	 * @return string
+	 */
+	public static function referrer()
+	{
+		return array_get($_SERVER, 'HTTP_REFERER');
+	}
+
 	/**
 	 * Determine if the current request is via the command line.
 	 *