【问题标题】:how to run the blade compiler explicitly?如何显式运行刀片编译器?
【发布时间】:2021-02-24 08:44:36
【问题描述】:

例如,在“resources/views/home.blade”有一个刀片文件,所以我们想将该文件编译成位于“root/public”位置的普通 php 文件,是否有任何工匠命令或任何东西做任务?

【问题讨论】:

  • 您可能必须自己调用编译器并在代码中执行此操作
  • 你可以在laravel存储中查看你的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);

【讨论】:

    猜你喜欢
    • 2020-02-09
    • 2016-07-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 2016-05-31
    • 1970-01-01
    • 2016-10-10
    • 1970-01-01
    相关资源
    最近更新 更多