From 43e20d71a0fa89ab35518c05c51de75b7943ac0b Mon Sep 17 00:00:00 2001 From: meowcakes Date: Sun, 3 Feb 2013 13:23:18 +1000 Subject: [PATCH] added segments method Needed a segments method to return all segments in an array --- src/Illuminate/Http/Request.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index cc113728b57d..4722f45bf95e 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -62,6 +62,20 @@ public function path() return $pattern == '' ? '/' : $pattern; } + + /** + * Get the URI segments + * + * @return array + */ + public function segments() + { + $segments = explode('/', trim($this->getPathInfo(), '/')); + + $segments = array_filter($segments, function($v) { return $v != ''; }); + + return $segments; + } /** * Get a segment from the URI (1 based index). @@ -72,11 +86,7 @@ public function path() */ public function segment($index, $default = null) { - $segments = explode('/', trim($this->getPathInfo(), '/')); - - $segments = array_filter($segments, function($v) { return $v != ''; }); - - return array_get($segments, $index - 1, $default); + return array_get($this->segments(), $index - 1, $default); } /**