So changing the Storage path in Laravel 5 is apparently more difficult than it possibly should be.
Here’s how I solved it with @stauffermatt ‘s tutorial to start but appended to make sure the storage path is stored in Config per. server rather than hardcoded into your Git stored php files.
- First follow Matt Stauffer’s tutorial, and add an application override
https://mattstauffer.co/blog/extending-laravels-application
# File /app/Application
<!--?php namespace App;
class Application extends Illuminate/Foundation/Application
{
/**
* Get the path to the storage directory.
*
* @return string
*/
public function storagePath()
{
return $this->basePath.'/theNewStorage';
}
}
- Then change your `bootstrap/app.php to…
$app = new AppApplication(
realpath(__DIR__.'/../')
);
- NOW, my extra bit. Create a
config/paths.example.php
and add it to git. Then duplicate it as,config/paths.php
, add that file to your.gitignore
and change the path to the server’s storage path.
<!--?php
return [
// Url to the server's storage file
// eg, 'storagePath' => "/var/www/storage",
'storagePath' => base_path()."/storage",
];
- Alter you
app/Application.php
file to load in the Config Repo with your new config file
<!--?php namespace App;
use Illuminate/Config/Repository as Config;
class Application extends Illuminate/Foundation/Application
{
/**
* Get the path to the storage directory.
*
* @return string
*/
public function storagePath()
{
$path = config_path(). '/paths.php';
$items = include $path;
$config = new Config($items);
return $config->get('storagePath');
}
}
There. Dunnit.