Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blade directive @guest #20114

Merged
merged 4 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,25 @@ protected function compileEndAuth()
{
return '<?php endif; ?>';
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra whitespace here, and your PR is perfect!

/**
* Compile the if-guest statements into valid PHP.
*
* @param string|null $guard
* @return string
*/
protected function compileGuest($guard = null)
{
return "<?php if(auth()->guard{$guard}->guest()): ?>";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be changed in #20087 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems taylor changed it...

a11b44a

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No guys!
This is not the guard which is passed, but the complete $expression, with the ().
Nothing to change here!

Copy link
Contributor

@m1guelpf m1guelpf Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mathieutu is rigth. There's nothing to change here.

}

/**
* Compile the end-guest statements into valid PHP.
*
* @return string
*/
protected function compileEndGuest()
{
return '<?php endif; ?>';
}
}
32 changes: 32 additions & 0 deletions tests/View/Blade/BladeIfGuestStatementsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Illuminate\Tests\Blade;

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\View\Compilers\BladeCompiler;

class BladeIfGuestStatementsTest extends TestCase
{
public function tearDown()
{
m::close();
}

public function testIfStatementsAreCompiled()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
$string = '@guest("api")
breeze
@endguest';
$expected = '<?php if(auth()->guard("api")->guest()): ?>
breeze
<?php endif; ?>';
$this->assertEquals($expected, $compiler->compileString($string));
}

protected function getFiles()
{
return m::mock('Illuminate\Filesystem\Filesystem');
}
}