【问题标题】:how to run the blade compiler explicitly?如何显式运行刀片编译器?
【发布时间】:2021-02-24 08:44:36
【问题描述】:
例如,在“resources/views/home.blade”有一个刀片文件,所以我们想将该文件编译成位于“root/public”位置的普通 php 文件,是否有任何工匠命令或任何东西做任务?
【问题讨论】:
标签:
php
laravel
laravel-blade
assets
【解决方案1】:
您可以直接使用BladeCompiler:
<?php
/** @var \Illuminate\View\Compilers\BladeCompiler */
$compiler = app('blade.compiler');
$srcPath = resource_path('views/home.blade.php');
$targetPath = public_path('home.php');
$compiled = $compiler->compileString(file_get_contents($srcPath));
file_put_contents($targetPath, $compiled);