You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I started using Laravel Zero recently and I faced an issue that I could not, for the life of me, seem to fix. And that is accessing "internal" files with the Storage facade. It was working well when the app was not bundled into a Phar. I saw this issue #177 where people were experimenting with the Phar::runing() function and after a lot of debugging I think I found a viable solution.
My problem was that I wanted to access files that were bundled with the Phar, at the same level as the app folder for example. It was working well with the dirname(app_path()) trick when not bundled, but it completely failed when it was bundled into a Phar. So I came up with the following steps and it worked!
Step 1: Filesystem configuration
Create a new config/filesystems.php file with the following content:
<?phpreturn [
'default' => 'local',
'disks' => [
'local' => [
'driver' => 'local',
// I usually place binaries in /bin, hence why the string manipulation// This part can be replace by `getcwd()`'root' => str(getcwd())->split('/\/bin/')->first()
],
'internal' => [
'driver' => 'local',
'root' => (Phar::running(false))
? Phar::running() . DIRECTORY_SEPARATOR// phar://SOMETHING/app/
: dirname(app_path())
]
]
];
If the Phar is running, it will return it's url + a directory separator, otherwise it will return the root folder of your Laravel Zero app.
Step 2: Include the folder in the box
Then you got to add the directory (in my case stubs) that you want to bundle with your app in the box.json:
And it will work whether the app is bundled or not.
I know it's probably not the best way to share this, but I wanted other people to be able to experiment with it and see if it works for them before opening a pull request on the documentation.
All I know is I would have been very happy to find something like this when I was looking for it
The text was updated successfully, but these errors were encountered:
Hi everyone 馃憢
I started using Laravel Zero recently and I faced an issue that I could not, for the life of me, seem to fix. And that is accessing "internal" files with the Storage facade. It was working well when the app was not bundled into a Phar. I saw this issue #177 where people were experimenting with the
Phar::runing()
function and after a lot of debugging I think I found a viable solution.My problem was that I wanted to access files that were bundled with the Phar, at the same level as the
app
folder for example. It was working well with thedirname(app_path())
trick when not bundled, but it completely failed when it was bundled into a Phar. So I came up with the following steps and it worked!Step 1: Filesystem configuration
Create a new
config/filesystems.php
file with the following content:If the Phar is running, it will return it's url + a directory separator, otherwise it will return the root folder of your Laravel Zero app.
Step 2: Include the folder in the box
Then you got to add the directory (in my case
stubs
) that you want to bundle with your app in thebox.json
:This way, when bundling the app, it will automatically include all the files included in that directory.
Step 3: Use the appropriate Storage Disk
Now, when you want to access a file in that folder (
stubs
) you can simply use the Storage facade with theinternal
disk:And it will work whether the app is bundled or not.
I know it's probably not the best way to share this, but I wanted other people to be able to experiment with it and see if it works for them before opening a pull request on the documentation.
All I know is I would have been very happy to find something like this when I was looking for it
The text was updated successfully, but these errors were encountered: