As already mentioned in some of the comments, the blade is not for the user to use php tags.
However, there are those who still prefer a solution in Blade
itself - like me.
Way 1 - The gambiarra
So the first option is to do a little gambiarra.
The Blade
compiles {{ $valor }}
to <?php echo $valor; ?>
- I have already opened the source code and I know it is so.
The solution would be to do this:
{{ ''; $valor = 1 }}
That would be compiled for this:
<?php echo ''; $valor = 1; ?>
It would still be possible to use the same gambiarra with the comments tag of Blade
.
{{-- */ $valor = 1; /* --}}
The output would be:
Way 2 - Extending the Blade
I prefer this second form, because a gambiarra always generates confusion and problems in the future.
We can extend Blade
and add a new syntax to your compiler. This is done using the Blade::extend(Closure $closure)
method.
For example, let's say that the expression {? $valor = 1 ?}
is interpreted by Blade
as <?php $valor = 1; ?>
.
Just add the following statement in the file app/start/global.php
:
Blade::extend(function($value) {
return preg_replace('/\{\?(.+)\?\}/', '<?php ${1} ?>', $value);
});