Laravel Storage is not able to locate file in Windows

665 views Asked by At

I am developing a package on Windows which publishes the package.php file in config directory of Laravel.

To get contents of package.php I am using Storage Facade. (I know I can use config() to read it but my usecase is different.)

use Illuminate\Support\Facades\Storage;
$contents = Storage::get(config_path('package.php'));

The above code is throwing FileNotFoundException but I have checked that the file is present there and I am also able to access it using config() helper.

File not found at path: C:/xampp/htdocs/blog/config/package.php

Interestingly when I print the config_path('package.php') it returns

"C:\xampp\htdocs\blog\config\package.php"

Notice that the direction of slashes is different in the path shown in Exception message and the path returned by config_path() helper.

I work mostly on Linux and hence not have much idea about Windows so I am not able to understand what;s going on here.

Please help!

Thanks.

1

There are 1 answers

0
Rohit Utekar On

Storage::get() will look only inside the root location configured for the disk. https://laravel.com/docs/8.x/filesystem#retrieving-files

You can use File facade instead of Storage.

File::get(config_path('package.php'));