laravel 生成静态页面的方法

废话不多说,直接上代码

$view = view('welcome')->with('data','xxx');

$html = response($view)->getContent();

if (file_exists(storage_path() .'/demo/1.html')) {
        return response()->file(storage_path() ."/demo/1.html");
}
if (! file_exists(storage_path() .'/demo')) {
        mkdir(storage_path() .'/demo');
}
file_put_contents(storage_path() ."/demo/".'1.html',$html);
chmod(storage_path() ."/demo/'1.html", '0777');
return response()->file(storage_path() ."/demo/1.html");
打赏作者

您将是第一位评论人!

提醒
avatar