2017-07-19 45 views
0

如何将内容放到*.blade.php文件中。我已经尝试了一些不同的方式,但我的*.blade.php仍然空白。laravel - 如何将内容放入Laravel的* .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文件?

感谢

你这 views

+0

也许权限问题? –

+0

@ S.I。我认为这不是权限问题,因为我为所有项目设置了777权限来测试该权限。但它仍然不起作用。 –

+0

检查你的缓存查看文件? – vijaykumar

回答

0

file_get_contents($file)只会工作,但你可以在这样

$file = 'hienthi'; 

$current = view($file)->render(); 

$current .= $request->code; // Get a content from $request->code 

File::put($file, $current); 

我希望这个控制器实现这有助于

+0

这仍然不起作用:(我的刀片仍然是空白的,什么都没有发生: –

0

问题这里是文件的地址。您的$file变量不包含视图目录中实际blade文件的位置。

你应该做到以下几点:

$file = resource_path() . "views/hienthi.blade.php"; 
//resource_path() is helper function to return path to resources directory 

你应该更喜欢使用Storage类的操作。

Storage::get(...) 
Storage::put(...) 

我无法测试,因为我旅行。一旦我有机会,我会更新这个答案。文件存储说明请参考官方docs

+0

仍然没有工作:(没有Nothings发生在我的刀片文件中,我已经清除了缓存但没有帮助,我将在官方文档中研究更多关于存储的问题。您。 –

相关问题