简体   繁体   中英

How it's done - Laravel Blade statements

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM