Skip to content

Commit c41fb3a

Browse files
Lukas Kämmerlingtaylorotwell
authored andcommitted
Add blade directive @guest (#20114)
* Update CompilesConditionals.php * Add Test * Fix Style CI * Fix Style CI #2
1 parent 919eee8 commit c41fb3a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,25 @@ protected function compileEndAuth()
119119
{
120120
return '<?php endif; ?>';
121121
}
122+
123+
/**
124+
* Compile the if-guest statements into valid PHP.
125+
*
126+
* @param string|null $guard
127+
* @return string
128+
*/
129+
protected function compileGuest($guard = null)
130+
{
131+
return "<?php if(auth()->guard{$guard}->guest()): ?>";
132+
}
133+
134+
/**
135+
* Compile the end-guest statements into valid PHP.
136+
*
137+
* @return string
138+
*/
139+
protected function compileEndGuest()
140+
{
141+
return '<?php endif; ?>';
142+
}
122143
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Blade;
4+
5+
use Mockery as m;
6+
use PHPUnit\Framework\TestCase;
7+
use Illuminate\View\Compilers\BladeCompiler;
8+
9+
class BladeIfGuestStatementsTest extends TestCase
10+
{
11+
public function tearDown()
12+
{
13+
m::close();
14+
}
15+
16+
public function testIfStatementsAreCompiled()
17+
{
18+
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
19+
$string = '@guest("api")
20+
breeze
21+
@endguest';
22+
$expected = '<?php if(auth()->guard("api")->guest()): ?>
23+
breeze
24+
<?php endif; ?>';
25+
$this->assertEquals($expected, $compiler->compileString($string));
26+
}
27+
28+
protected function getFiles()
29+
{
30+
return m::mock('Illuminate\Filesystem\Filesystem');
31+
}
32+
}

0 commit comments

Comments
 (0)