How to get Blade template view as a raw HTML string?

Yevgeniy Afanasyev picture Yevgeniy Afanasyev · Jun 20, 2018 · Viewed 39.2k times · Source

I need the HTML of my Blade template as a string.

I'm going to use that HTML string to generate a PDF from it.

At the moment I have Blade streaming as a response back to browsers.

 return view('users.edit', compact('user'));

How can I get the raw HTML string from the blade template?

Answer

fubar picture fubar · Jun 20, 2018

You can call render() on the view.

$html = view('users.edit', compact('user'))->render();

See the View source code for more information.