diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index c70b0b5158c8..2fb1406ca47d 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -435,6 +435,12 @@ public function if($name, callable $callback) : ""; }); + $this->directive('unless'.$name, function ($expression) use ($name) { + return $expression !== '' + ? "" + : ""; + }); + $this->directive('else'.$name, function ($expression) use ($name) { return $expression !== '' ? "" diff --git a/tests/View/Blade/BladeCustomTest.php b/tests/View/Blade/BladeCustomTest.php index 8afd1ebdd677..b2b947aa115b 100644 --- a/tests/View/Blade/BladeCustomTest.php +++ b/tests/View/Blade/BladeCustomTest.php @@ -127,6 +127,19 @@ public function testCustomIfElseConditions() $this->assertEquals($expected, $this->compiler->compileString($string)); } + public function testCustomUnlessConditions() + { + $this->compiler->if('custom', function ($anything) { + return true; + }); + + $string = '@unlesscustom($user) +@endcustom'; + $expected = ' +'; + $this->assertEquals($expected, $this->compiler->compileString($string)); + } + public function testCustomConditionsAccepts0AsArgument() { $this->compiler->if('custom', function ($number) {