Skip to content
Advertisement

how to run the blade compiler explicitly?

for example there is a blade file at “⁨resources⁩/views/home.blade” so we want to compile the file into plain php file at location “root/⁩public”, is there any artisan command or anything to do the task?

Advertisement

Answer

You can use the BladeCompiler directly:

<?php

/** @var IlluminateViewCompilersBladeCompiler */
$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);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement