Laravel Blade Templates Execute arbitrary PHP code


Example

Although it might not be proper to do such thing in a view if you intend to separate concerns strictly, the php Blade directive allows a way to execute PHP code, for instance, to set a variable:

@php($varName = 'Enter content ')

(same as:)

@php
    $varName = 'Enter content ';
@endphp

later:

{{ $varName }}

Result:

Enter content