Ad

Laravel Storage_path For Shell Script

- 1 answer

I have a Laravel app that needs to run a shell script, to do so I'm using exec(). The shell script creates a file that I want to store in my storage folder, however the shell script requires the path for the storage folder.

If I use storage_path() it returns something like "/home/vagrant/project/storage" which works fine when it comes to referencing things within my web app, but as far as the shell script is concerned isn't correct. The correct path on homestead would be: ~/project/storage and on live/staging it would be something like /var/www/project/storage.

Is there a elegant way of Laravel acquiring the exact path to pass to the shell script or am I going to have to specify it in my .env file and use that instead?

Ad

Answer

Default value returned by storage_path() always points to storage/ folder in your project's root. Regardless in which folder you put your project application, value returned by the helper will be correct.

If you want to change the default value of storage_path, you can do so with App::useStoragePath($path). If this value should be different for different environments you need to read the path from .env file - that's what it is for.

App::useStoragePath(env('STORAGE_PATH'));
Ad
source: stackoverflow.com
Ad