目前在我的项目根目录上,我有
/checklist_templates
checklist-test.txt
在我的一个控制器中,我想在我的index()
方法中读取该文件。
public function index()
{
$contents = File::get('/checklist_templates/checklist-test.txt');
}
但是由于某种原因,我不断收到错误:
File does not exist at path /checklist_templates/checklist-test.txt
有人知道是什么原因造成的吗?谢谢。
我能够解决自己的答案。我猜 Laravel 在打开文件时想要完整的路由,所以我不得不使用以下方法:
$contents = File::get(base_path('/checklist_templates/checklist-test.txt'));