Permalink
Browse files

add csrf and method blade directives

  • Loading branch information...
taylorotwell committed Dec 1, 2017
1 parent 6563ba6 commit 5f1984421af096ef21b7d2011949a233849d4ee3
@@ -12,6 +12,7 @@ class BladeCompiler extends Compiler implements CompilerInterface
Concerns\CompilesComponents,
Concerns\CompilesConditionals,
Concerns\CompilesEchos,
Concerns\CompilesFormHelpers,
Concerns\CompilesIncludes,
Concerns\CompilesInjections,
Concerns\CompilesJson,
@@ -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}; ?>";
}
}
@@ -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

This comment has been minimized.

Contributor

m1guelpf replied Dec 1, 2017

@taylorotwell Why master and not 5.5?

@connectkushal

This comment has been minimized.

Contributor

connectkushal replied Dec 25, 2017

cool stuff 😎

@JPortegijs

This comment has been minimized.

JPortegijs replied Jan 31, 2018

Ugh, my OCD! Why is the first method written with single quotes and the second with double quotes! 😄

@m1guelpf

This comment has been minimized.

Contributor

m1guelpf replied Jan 31, 2018

@JPortegijs The second method uses a variable.

Please sign in to comment.