Skip to content

Commit

Permalink
add csrf and method blade directives
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 1, 2017
1 parent 6563ba6 commit 5f19844
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BladeCompiler extends Compiler implements CompilerInterface
Concerns\CompilesComponents,
Concerns\CompilesConditionals,
Concerns\CompilesEchos,
Concerns\CompilesFormHelpers,
Concerns\CompilesIncludes,
Concerns\CompilesInjections,
Concerns\CompilesJson,
Expand Down
27 changes: 27 additions & 0 deletions src/Illuminate/View/Compilers/Concerns/CompilesFormHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Illuminate\View\Compilers\Concerns;

trait CompilesFormHelpers
{
/**
* Compile the CSRF statements into valid PHP.
*
* @return string
*/
protected function compileCsrf()
{
return '<?php echo csrf_field(); ?>';
}

/*
* Compile the method statements into valid PHP.
*
* @param string $method
* @return string
*/
protected function compileMethod($method)
{
return "<?php echo method_field{$method}; ?>";
}
}
12 changes: 12 additions & 0 deletions tests/View/Blade/BladeFormHelpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Illuminate\Tests\View\Blade;

class BladeFormHelpersTest extends AbstractBladeTestCase
{
public function testEchosAreCompiled()
{
$this->assertEquals('<?php echo csrf_field(); ?>', $this->compiler->compileString('@csrf'));
$this->assertEquals('<?php echo method_field(\'patch\'); ?>', $this->compiler->compileString("@method('patch')"));
}
}

4 comments on commit 5f19844

@m1guelpf
Copy link
Contributor

Choose a reason for hiding this comment

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

@taylorotwell Why master and not 5.5?

@connectkushal
Copy link
Contributor

Choose a reason for hiding this comment

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

cool stuff 😎

@JPortegijs
Copy link

Choose a reason for hiding this comment

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

Ugh, my OCD! Why is the first method written with single quotes and the second with double quotes! πŸ˜„

@m1guelpf
Copy link
Contributor

Choose a reason for hiding this comment

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

@JPortegijs The second method uses a variable.

Please sign in to comment.