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

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


You can call render() on the view.

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

See the View source code for more information.


    <!-- View stored in resources/views/greeting.blade.php -->    <html>        <body>            <h1>Hello, {{ $name }}</h1>        </body>    </html><!-- In your php controller  -->        return view('greeting', ['name' => 'James']);

edited

<!-- In your PHP controller You can add html variable , and then use it for example to print PDF -->$html=view('greeting', ['name' => 'James']); $pdf = \App::make('snappy.pdf.wrapper'); $output = $pdf->loadHTML($html)->output();$headers = [            'Content-Type' => 'application/pdf',            'Content-Disposition' => 'inline; filename="' . $filename . '"',        ];        \Storage::put("pdfs/$filename", $output);return response()->download(storage_path("app\\pdfs\\$filename"), $filename . '.pdf', $headers);<!-- or return \Response::make($output, 200, $headers); -->