diff --git a/src/Illuminate/View/Concerns/ManagesLayouts.php b/src/Illuminate/View/Concerns/ManagesLayouts.php index cd494f8e0aa5..1224ee82c227 100644 --- a/src/Illuminate/View/Concerns/ManagesLayouts.php +++ b/src/Illuminate/View/Concerns/ManagesLayouts.php @@ -182,6 +182,18 @@ public function hasSection($name) return array_key_exists($name, $this->sections); } + /** + * Get the contents of a section. + * + * @param string $name + * @param string $default + * @return mixed + */ + public function getSection($name, $default = null) + { + return isset($this->getSections()[$name]) ? $this->getSections()[$name] : $default; + } + /** * Get the entire array of sections. * diff --git a/tests/View/ViewFactoryTest.php b/tests/View/ViewFactoryTest.php index 695a711e53fb..23afb6157e4f 100755 --- a/tests/View/ViewFactoryTest.php +++ b/tests/View/ViewFactoryTest.php @@ -349,6 +349,18 @@ public function testHasSection() $this->assertFalse($factory->hasSection('bar')); } + public function testGetSection() + { + $factory = $this->getFactory(); + $factory->startSection('foo'); + echo 'hi'; + $factory->stopSection(); + + $this->assertEquals('hi', $factory->getSection('foo')); + $this->assertNull($factory->getSection('bar')); + $this->assertEquals('default', $factory->getSection('bar', 'default')); + } + public function testMakeWithSlashAndDot() { $factory = $this->getFactory();