I am trying to move the public
folder to other place. However, I can't find the place to modify public_path()
variable. Now, the 'public_path()' return the wrong path of folder.
Where can I set the variable for public_path()
?
I am trying to move the public
folder to other place. However, I can't find the place to modify public_path()
variable. Now, the 'public_path()' return the wrong path of folder.
Where can I set the variable for public_path()
?
I suggest you add it in
app/Providers/AppServiceProvider.php
:This affects
artisan
as well.You can override the public path using ioc container :
What worked for me flawlessly was adding to
public/index.php
the following three lines:For more detailed explanation click here
In laravel 5.6 this work for me ... adding this code to bootstrap/app.php :
where __DIR__.'/../' is path to your public folder
While accepted answer works for requests coming from HTTP, it will not work for
artisan
.If you need
artisan
to know your custom public path, you need to extend Laravel main Application class. I know it sounds scary, but it's actually very simple.All you need to do is following:
Step 1: In the file:
bootstrap/app.php
change the very first declaration of$app
variableto reflect your own custom Application class:
Step 2: Define your custom Application class somewhere. For example in
app/Application.php
Congrats! You have extended Laravel core Application class.
Step 3: Overwrite the
publicPath
method. Copy and paste Laravel original method to your new class and change it to your needs. In my particular case I did like this:That's it! You can overwrite any method in Application class the same way.