diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index 3638291f3446..24a521161638 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -387,6 +387,12 @@ public function if($name, callable $callback) : ""; }); + $this->directive('else'.$name, function ($expression) use ($name) { + return $expression + ? "" + : ""; + }); + $this->directive('end'.$name, function () { return ''; }); diff --git a/tests/View/Blade/BladeCustomTest.php b/tests/View/Blade/BladeCustomTest.php index 510b1c1d551c..368fc793ecad 100644 --- a/tests/View/Blade/BladeCustomTest.php +++ b/tests/View/Blade/BladeCustomTest.php @@ -70,6 +70,23 @@ public function testCustomConditions() $string = '@custom($user) @endcustom'; $expected = ' +'; + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + + public function testCustomIfElseConditions() + { + $this->compiler->if('custom', function ($anything) { + return true; + }); + + $string = '@custom($user) +@elsecustom($product) +@else +@endcustom'; + $expected = ' + + '; $this->assertEquals($expected, $this->compiler->compileString($string)); }