Answers for "when image update laravel delete remove image"

PHP
1

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);
}
Posted by: Guest on April-21-2021
0

when image update laravel delete remove image

public function update($id)
{
      $article = Article::find($id);
    
    if(Input::hasFile('image'))
    {
             $file = Input::file('image');
             $name = time() . '-' . $file->getClientOriginalName();
             $file = $file->move(public_path() . '/images/profile/', $name);
             $article->file= $name;
    }
    $article->save();
    return "success";
}
Posted by: Guest on April-21-2021

Code answers related to "when image update laravel delete remove image"

Browse Popular Code Answers by Language