使用 Laravel 5.8 部署到生产环境会删除我的 public 上传存储目录

Deploying to production with Laravel 5.8 deletes my public uploads storage directory

我正在 Laravel 5.8 上构建我的第一个网站,大部分情况下一切正常。我可以创建一个新的 Post,上传一张照片,点击保存,记录保存到数据库中,我可以在我的视图、图像和所有内容中看到 Post 数据。我将我的更改推送到我的生产服务器,创建一个新的 Post、图像等......一切似乎都很好。直到,我从我的本地环境中推送了另一个更改,然后我意识到我的 public/uploads 目录被清除了,上传到 Post 的任何图像都有损坏的图像 link.

我的设置

Laravel 5.8(本地和生产),MySql 5.7(本地和生产),Valet(本地),推送到 Bitbucket,Envoyer Pulls Changes and Auto deploys, Digital Ocean Droplet set via Forge

filesystems.php

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

PostController.php

public function store(Request $request)
{

    $rules = [
        'title' => ['required', 'min:3'],
        'body' => ['required', 'min:5'],
        'photo' => 'image|mimes:jpeg,png,jpg,gif|max:4096M'
    ];
    $request->validate($rules);
    $user_id = Auth::id();
    $post = new Post();
    $post->user_id = $user_id;
    $post->is_featured = $request->input('is_featured', false);
    $post->is_place = $request->input('is_place', false);
    $post->title = request('title');
    $post->body = request('body');
    $post->place_name = request('place_name');
    $post->place_address = request('place_address');
    $post->place_city = request('place_city');
    $post->place_state = request('place_state');
    $post->place_zip = request('place_zip');
    $post->place_phone = request('place_phone');
    $post->place_email = request('place_email');
    $post->place_website = request('place_website');

    if ($request->has('photo')) {
        // Get image file
        $image = $request->file('photo');
        // Make a image name based on user name and current timestamp
        $name = Str::slug($request->input('name')).time();
        // Define folder path
        $folder = '/uploads/posts/' . $user_id . '/';
        // Make a file path where image will be stored [ folder path + file name + file extension]
        $filePath = $folder . $name. '.' . $image->getClientOriginalExtension();
        // Upload image
        $this->uploadOne($image, $folder, 'public', $name);
        // Set user profile image path in database to filePath
        $post->photo = $filePath;
    }

    $post->save();

    $posts = Post::all();
    return view('backend.auth.post.index', compact('posts'));
}

此文件夹可能未版本化

在文件夹 (public/uploads) 中添加一个空 .gitkeep 文件,提交、推送并重新部署。

Git 不保留空文件夹。