Skip to content

Commit 5f19844

Browse files
committed
add csrf and method blade directives
1 parent 6563ba6 commit 5f19844

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Diff for: src/Illuminate/View/Compilers/BladeCompiler.php

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class BladeCompiler extends Compiler implements CompilerInterface
1212
Concerns\CompilesComponents,
1313
Concerns\CompilesConditionals,
1414
Concerns\CompilesEchos,
15+
Concerns\CompilesFormHelpers,
1516
Concerns\CompilesIncludes,
1617
Concerns\CompilesInjections,
1718
Concerns\CompilesJson,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Illuminate\View\Compilers\Concerns;
4+
5+
trait CompilesFormHelpers
6+
{
7+
/**
8+
* Compile the CSRF statements into valid PHP.
9+
*
10+
* @return string
11+
*/
12+
protected function compileCsrf()
13+
{
14+
return '<?php echo csrf_field(); ?>';
15+
}
16+
17+
/*
18+
* Compile the method statements into valid PHP.
19+
*
20+
* @param string $method
21+
* @return string
22+
*/
23+
protected function compileMethod($method)
24+
{
25+
return "<?php echo method_field{$method}; ?>";
26+
}
27+
}

Diff for: tests/View/Blade/BladeFormHelpersTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\View\Blade;
4+
5+
class BladeFormHelpersTest extends AbstractBladeTestCase
6+
{
7+
public function testEchosAreCompiled()
8+
{
9+
$this->assertEquals('<?php echo csrf_field(); ?>', $this->compiler->compileString('@csrf'));
10+
$this->assertEquals('<?php echo method_field(\'patch\'); ?>', $this->compiler->compileString("@method('patch')"));
11+
}
12+
}

0 commit comments

Comments
 (0)