覆盖 Laravel Voyager 默认图片上传路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47449682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:00:05  来源:igfitidea点击:

Override Laravel Voyager default Image Upload Path

imagelaravelpathuploadvoyager

提问by Annapurna

The Voyager by default uploads the images to storage/app/public/posts folder for posts' featured images. I want to change it to a custom folder in my public folder.

默认情况下,Voyager 将图像上传到 storage/app/public/posts 文件夹,用于帖子的精选图像。我想将其更改为公共文件夹中的自定义文件夹。

How do I achieve this?

我如何实现这一目标?

Thanks in advance.

提前致谢。

回答by Tpojka

Open config/filesystems.phpfile and check thissection. Add one more key like voyagerfor example.

打开config/filesystems.php文件并检查部分。再添加一个键voyager,例如。

'disks' => [
    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],
    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],
    's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
    ],
    'voyager' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),// change here something specific to your application need
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],
],

Then open config/voyager.phpfileand set that key ('voyager') instead of 'public' like this:

然后打开config/voyager.php文件并设置该键 ( 'voyager') 而不是“public”,如下所示:

'storage' => [
    'disk' => 'voyager',
],

回答by Umar Tariq

Go to the config/filesystems.php and change the root and URL key for your new folder. See below the example

转到 config/filesystems.php 并更改新文件夹的根和 URL 键。看下面的例子

    'public' => [
        'driver' => 'local',
        'root' => public_path().'/app', //Add new folder into public folder called app
        'url' => env('APP_URL').'/public/app', //change get path for image 
        'visibility' => 'public',
    ],