Skip to content

Commit 6f4480b

Browse files
committed
add selected directive
1 parent 84d433d commit 6f4480b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ public function compileEndOnce()
305305
return '<?php endif; ?>';
306306
}
307307

308+
/**
309+
* Compile a selected block into valid PHP.
310+
*
311+
* @param string $condition
312+
* @return string
313+
*/
314+
protected function compileSelected($condition)
315+
{
316+
return "<?php if{$condition}: echo 'selected'; endif; ?>";
317+
}
318+
308319
/**
309320
* Compile a checked block into valid PHP.
310321
*

tests/View/Blade/BladeCheckedStatementsTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
class BladeCheckedStatementsTest extends AbstractBladeTestCase
66
{
7+
public function testSelectedStatementsAreCompiled()
8+
{
9+
$string = '<input @selected(name(foo(bar)))/>';
10+
$expected = "<input <?php if(name(foo(bar))): echo 'selected'; endif; ?>/>";
11+
12+
$this->assertEquals($expected, $this->compiler->compileString($string));
13+
}
14+
715
public function testCheckedStatementsAreCompiled()
816
{
917
$string = '<input @checked(name(foo(bar)))/>';

0 commit comments

Comments
 (0)