如何获取 Laravel 视图渲染后的字符串内容
$html = View::make('foo', ['bar' => 'baz'])->render();
或者 view() 方法:
$html = view('foo', ['bar' => 'baz'])->render();
请尽量避免使用强制类型转换 (string) View::make() 方法来获取字符串类型的数据。此种方法有时会引发 『Method __toString() must not throw and exception』的异常报错,而掩盖了 View 中原本正常的报错,会对定位报错造成不便。
$html = (string) view('foo', ['bar' => 'baz']);
$html = view('foo', ['bar' => 'baz'])->__toString();