Skip to content

Commit

Permalink
Add @cannot Blade directive
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbean committed Sep 1, 2015
1 parent 47ed05d commit 9c41aa0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,17 @@ protected function compileCan($expression)
return "<?php if (Gate::check{$expression}): ?>";
}

/**
* Compile the cannot statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileCannot($expression)
{
return "<?php if (Gate::denies{$expression}): ?>";
}

/**
* Compile the if statements into valid PHP.
*
Expand Down Expand Up @@ -640,6 +651,17 @@ protected function compileEndcan($expression)
return '<?php endif; ?>';
}

/**
* Compile the end-cannot statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileEndcannot($expression)
{
return '<?php endif; ?>';
}

/**
* Compile the end-if statements into valid PHP.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/View/ViewBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ public function testCanStatementsAreCompiled()
$this->assertEquals($expected, $compiler->compileString($string));
}

public function testCannotStatementsAreCompiled()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
$string = '@cannot (\'update\', [$post])
breeze
@endcannot';
$expected = '<?php if (Gate::denies(\'update\', [$post])): ?>
breeze
<?php endif; ?>';
$this->assertEquals($expected, $compiler->compileString($string));
}

public function testElseStatementsAreCompiled()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
Expand Down

0 comments on commit 9c41aa0

Please sign in to comment.