Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the storage path in Laravel 5

I want to change the storage path Laravel 5.1 uses to something like /home/test/storage. This has the advantage that these files are not stored in the repository, which is fairly ugly I think. In Laravel 4 this was very simple with bootstrap/paths.php.

In Laravel 5 it this works by using $app->useStoragePath('/path/') in bootstrap/app.php. However, I want to define the storage path with a config option, like $app->useStoragePath(config('app.storage_path'). The config option calls an environment variable or returns a default location.

Doing this results in a Uncaught exception 'ReflectionException' with message 'Class config does not exist'; this makes sense, because this function is not loaded yet.

I tried setting the storage path just after booting:

$app->booted(function () use ($app) {
    $app->useStoragePath(config('app.storage_root'));
});

This changed nothing. I also tried directly binding it to path.storage:

$app->bind('path.storage', function ($app) {
    return config('app.storage_root');
});

The last option works partially; the view cache is now placed in the correct location, but the logs are still at the old location.

like image 368
spacek33z Avatar asked Aug 05 '15 19:08

spacek33z


People also ask

How do I change storage location in Laravel?

In Laravel 5 it this works by using $app->useStoragePath('/path/') in bootstrap/app. php .

Where is Laravel storage path?

Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.

How do I save to storage folder in Laravel?

Now, if you need to change the directory and store into the storage folder directly, you need to change something in the filesystems. php file. 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), ], Here, this line of code 'root' => storage_path('app'), responsible to define where to store.


1 Answers

Set it up in .env

app.php

'app_storage' => env('APP_STORAGE', storage_path()),

app/Providers/AppServiceProvider.php

public function register()
{
    $this->app->useStoragePath(config('app.app_storage'));
}

.env

APP_STORAGE=custom_location
like image 167
M Holod Avatar answered Oct 05 '22 23:10

M Holod