Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

deromanenko's avatar

get View as a string

Hello! In my application I want to gave to users possibility to create some documents (invoices, specifications, other) by themselves. It's easy, cause they all knows html. Templates of documents stored in database. In templates we use Blade directives to list products, show properties of product, etc.

It works well, when view returns to the browser. But I want also get it as a string and save it

But when I use code like this

$compiled = return view('dope')->with('products', $products);

I get object, but not string. What should I use?

(Blade::compileString not work at all)

0 likes
5 replies
codenex's avatar

You didn't show how you populated the $products variable so it's going to be hard to give you an answer.

SaeedPrez's avatar
Level 50

Hi @deromanenko, try this..

$compiled = view('dope')->with('products', $products)->render();
4 likes

Please or to participate in this conversation.