How it's done - Laravel Blade statements

359 Views Asked by At

How it is done, that we can have for example something like this in a blade view:

@if (count($records) === 1) 
(...)

After analyzing the bladeCompiler.php file, I can see that this is converted to PHP, there is for example a method like this:

protected function compileIf($expression)
{
    return "<?php if{$expression}: ?>";
}

It is then indirectly used by "compileString" method, which takes and returns a string.

But what then? I can't find an occurence of the PHP's "eval" function call in the entire project, so how it's done?

1

There are 1 best solutions below

2
On BEST ANSWER

After Blade has compiled the PHP code, Laravel puts the result into a cached file in the storage/framework/views/ directory. That file is then called directly, so you don't need any eval() statements.