如何在Laravel应用程序中查找特定文件?

如何在Laravel应用程序中查找特定文件?,laravel,laravel-5,Laravel,Laravel 5,我有一个PHP文件,位于holiday/app/Console/Commands/myCommand.PHP,其中包含: namespace Holiday\Console\Commands; $bob = file_get_contents('Storage/data/BE.json'); 它是有效的 但是在holiday/app/Http/Controllers/holidayController.php中,我有: namespace Holiday\Http\Controllers;

我有一个PHP文件,位于
holiday/app/Console/Commands/myCommand.PHP
,其中包含:

namespace Holiday\Console\Commands; 

$bob = file_get_contents('Storage/data/BE.json');
它是有效的

但是在
holiday/app/Http/Controllers/holidayController.php
中,我有:

namespace Holiday\Http\Controllers; 

$bob = file_get_contents('Storage/data/BE.json');
但我明白了

file_get_contents(Holiday/Storage/data/BE.json): failed to open stream: 
No such file or directory

有人知道这是为什么吗?

您应该始终使用助手来获得正确的路径。在这里,使用helper。例如:

file_get_contents(storage_path('data/BE.json'))
这将创建到
laravel_项目/storage/data/BE.json
文件的正确路径