Laravel storage link 没有指向磁盘路径(指向默认路径)

Laravel storage link doesn't point to the disk path (point to the default path)

我正在使用 laravel 8 和 Mediable 库来管理我的媒体。在 public_html(主域)中一切正常,但子域中的网站副本在存储路径中保存媒体时出错。 我的 filesystems.php:

'disks' => [
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
    ],

我正在尝试这样保存我的媒体:

$picture = MediaUploader::fromSource($request->file('picture'))
                ->toDestination('public', 'gallery')
                ->onDuplicateIncrement()
                ->useHashForFilename()
                ->upload();
                
$gallery->attachMedia($picture, ['gallery']);

但是保存图片后,{Domain}/storage/gallery/{image} 图像的 url 应该指向 storage/app/public/gallery 但它指向默认位置 public/storage/gallery

答案是指向我需要的存储目录的符号链接,在 index.php 中使用此代码:

$app->bind('path.public', function () {
    return __DIR__;
});

然后使用php artisan storage:link建立到存储目录的符号链接

注意:如果您使用共享主机并且无法访问 shell,请在您的 web.php:

中像这样使用 Artisan 门面
Route::get('link', function() {
    $exitCode = Artisan::call('storage:link');
    dd(Artisan::output());
});

然后调用{Domain}/linkurl到运行artisan命令