Is there any way to compile a blade template from a string?

I found the solution by extending BladeCompiler. <?php namespace Laravel\Enhanced; use Illuminate\View\Compilers\BladeCompiler as LaravelBladeCompiler; class BladeCompiler extends LaravelBladeCompiler { /** * Compile blade template with passing arguments. * * @param string $value HTML-code including blade * @param array $args Array of values used in blade * @return string */ public function compileWiths($value, array $args = … Read more

Passing a PHP variable to JavaScript in a Blade template

One working example for me. Controller: public function tableView() { $sites = Site::all(); return view(‘main.table’, compact(‘sites’)); } View: <script> var sites = {!! json_encode($sites->toArray()) !!}; </script> To prevent malicious / unintended behaviour, you can use JSON_HEX_TAG as suggested by Jon in the comment that links to this SO answer <script> var sites = {!! json_encode($sites->toArray(), … Read more