You can stretch the blade like this:
Blade::directive('switch', function ($expression) { return "<?php switch($expression): ?>"; }); Blade::directive('case', function ($expression) { return "<?php case $expression: ?>"; }); Blade::directive('break', function () { return "<?php break; ?>"; }); Blade::directive('default', function () { return "<?php default: ?>"; }); Blade::directive('endswitch', function () { return "<?php endswitch; ?>"; });
Then you can use the following:
@switch($test) @case(1) Words @break @case(2) Other Words @break @default Default words @endswitch
However, pay attention to the warnings at: http://php.net/manual/en/control-structures.alternative-syntax.php
If there are spaces between the switch (): and the first case, then the entire code block will fail. This is a limitation of PHP, not a limitation of the blade. You can get around it by calling the normal syntax, for example:
Blade::directive('switch', function ($expression) { return "<?php switch($expression) { ?>"; }); Blade::directive('endswitch', function ($) { return "<?php } ?>"; });
But this is a little wrong.
apokryfos Jun 20 '17 at 10:17 2017-06-20 10:17
source share