📜  当图像更新 laravel 删除删除图像 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:37.550000             🧑  作者: Mango

代码示例1
public function update(Post $post){
    $this->validateRequest();
    $data = [
        'title' => request()->title,
        'content' => request()->content
    ];
    if (request()->hasFile('image') && request('image') != '') {
        $imagePath = public_path('storage/'.$post->image);
        if(File::exists($imagePath)){
            unlink($imagePath);
        }
        $image = request()->file('image')->store('uploads', 'public');
        $data['image'] = $image;
        $post->update($data);
    }
    $post->update($data);
}