如何将内容放入*.blade.php
文件。我已经尝试了一些不同的方式,但我的*.blade.php
仍然空白。
$file = 'hienthi.blade.php';
$current = file_get_contents($file);
$current .= $request->code; // Get a content from $request->code
File::put($file, $current);
或
$fp = fopen('hienthi.blade.php', 'w');
fwrite($fp, $request->code); // Get a content from $request->code
fclose($fp);
当我使用上述两种方式时,我的hienthi.blade.php
仍为空白。
似乎file_put_content
函数只是使用txt文件?
无论如何将内容放到*.blade.php
文件中?
由于
答案 0 :(得分:0)
file_get_contents($file)
只有在views
但你可以在控制器中实现这个
$file = 'hienthi';
$current = view($file)->render();
$current .= $request->code; // Get a content from $request->code
File::put($file, $current);
我希望这会有所帮助
答案 1 :(得分:0)
The problem here is the address of the file. Your $file
variable doesn't contain the location of the actual blade
file in the views directory.
You should do the following:
$file = resource_path() . "views/hienthi.blade.php";
//resource_path() is helper function to return path to resources directory
And you should prefer to use Storage
class for the manipulation.
Storage::get(...)
Storage::put(...)
I couldn't test this because I am travelling. I'll update this answer once I get the chance. Refer to official docs的文本值以获取文件存储说明。