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

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?


You can call render() on the view.

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

See the View source code for more information.


This is the perfect solution of download/converting a blade file to HTML.

$view = view('welcome')->render();
header("Content-type: text/html");
header("Content-Disposition: attachment; filename=view.html");
return $view;