更改Laravel 5中的存储路径

问题描述 投票:12回答:6

我想将Laravel 5.1使用的存储路径更改为/home/test/storage。这样做的好处是这些文件没有存储在存储库中,我认为这非常难看。在Laravel 4中,使用bootstrap/paths.php非常简单。

在Laravel 5中,这通过使用$app->useStoragePath('/path/')中的bootstrap/app.php起作用。但是,我想使用config选项定义存储路径,例如$app->useStoragePath(config('app.storage_path')。 config选项调用环境变量或返回默认位置。

执行此操作将得到Uncaught exception 'ReflectionException' with message 'Class config does not exist';这很有道理,因为尚未加载此功能。

启动后我试图设置存储路径:

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

这没有改变。我也尝试将其直接绑定到path.storage

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

最后一个选项部分起作用;现在,视图缓存已放置在正确的位置,但是日志仍在旧位置。

php laravel laravel-5.1
6个回答
6
投票
Laravel 5中存储路径的简单解决方案,就像我们在

Laravel 4中所做的一样在bootstrap / app.php上

# new storage path # base_path() -> returns root path $path_storage = base_path() . "../../storage"; # override already $app->storagePath using the function $app->useStoragePath($path_storage);

这将使存储路径与会话,视图,缓存,日志相同


6
投票
bootstrap / app.php

4
投票

1
投票

0
投票

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.