diff --git a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php index 9f058b995cbc..d592ef1771f0 100644 --- a/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php +++ b/src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php @@ -24,6 +24,19 @@ protected function compileAuth($guard = null) return "guard{$guard}->check()): ?>"; } + /** + * Compile the else-auth statements into valid PHP. + * + * @param string|null $guard + * @return string + */ + protected function compileElseAuth($guard = null) + { + $guard = is_null($guard) ? '()' : $guard; + + return "guard{$guard}->check()): ?>"; + } + /** * Compile the end-auth statements into valid PHP. * @@ -47,6 +60,19 @@ protected function compileGuest($guard = null) return "guard{$guard}->guest()): ?>"; } + /** + * Compile the else-guest statements into valid PHP. + * + * @param string|null $guard + * @return string + */ + protected function compileElseGuest($guard = null) + { + $guard = is_null($guard) ? '()' : $guard; + + return "guard{$guard}->guest()): ?>"; + } + /** * Compile the end-guest statements into valid PHP. * diff --git a/tests/View/Blade/BladeElseAuthStatementsTest.php b/tests/View/Blade/BladeElseAuthStatementsTest.php new file mode 100644 index 000000000000..b978d4989cdd --- /dev/null +++ b/tests/View/Blade/BladeElseAuthStatementsTest.php @@ -0,0 +1,52 @@ +getFiles(), __DIR__); + $string = '@auth("api") +breeze +@elseauth("standard") +wheeze +@endauth'; + $expected = 'guard("api")->check()): ?> +breeze +guard("standard")->check()): ?> +wheeze +'; + $this->assertEquals($expected, $compiler->compileString($string)); + } + + public function testPlainElseAuthStatementsAreCompiled() + { + $compiler = new BladeCompiler($this->getFiles(), __DIR__); + $string = '@auth("api") +breeze +@elseauth +wheeze +@endauth'; + $expected = 'guard("api")->check()): ?> +breeze +guard()->check()): ?> +wheeze +'; + $this->assertEquals($expected, $compiler->compileString($string)); + } + + protected function getFiles() + { + return m::mock('Illuminate\Filesystem\Filesystem'); + } +} diff --git a/tests/View/Blade/BladeElseGuestStatementsTest.php b/tests/View/Blade/BladeElseGuestStatementsTest.php new file mode 100644 index 000000000000..9da4032676a1 --- /dev/null +++ b/tests/View/Blade/BladeElseGuestStatementsTest.php @@ -0,0 +1,36 @@ +getFiles(), __DIR__); + $string = '@guest("api") +breeze +@elseguest("standard") +wheeze +@endguest'; + $expected = 'guard("api")->guest()): ?> +breeze +guard("standard")->guest()): ?> +wheeze +'; + $this->assertEquals($expected, $compiler->compileString($string)); + } + + protected function getFiles() + { + return m::mock('Illuminate\Filesystem\Filesystem'); + } +}