Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

when image update laravel delete remove image

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);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #image #update #laravel #delete #remove #image
ADD COMMENT
Topic
Name
2+3 =