when image update laravel delete remove image

Solutions on MaxInterview for when image update laravel delete remove image by the best coders in the world

showing results for - "when image update laravel delete remove image"
Jonah
30 Oct 2020
1public function update(Post $post){
2    $this->validateRequest();
3    $data = [
4        'title' => request()->title,
5        'content' => request()->content
6    ];
7    if (request()->hasFile('image') && request('image') != '') {
8        $imagePath = public_path('storage/'.$post->image);
9        if(File::exists($imagePath)){
10            unlink($imagePath);
11        }
12        $image = request()->file('image')->store('uploads', 'public');
13        $data['image'] = $image;
14        $post->update($data);
15    }
16    $post->update($data);
17}
18
Elena
25 Mar 2016
1public function update($id)
2{
3      $article = Article::find($id);
4    
5    if(Input::hasFile('image'))
6    {
7             $file = Input::file('image');
8             $name = time() . '-' . $file->getClientOriginalName();
9             $file = $file->move(public_path() . '/images/profile/', $name);
10             $article->file= $name;
11    }
12    $article->save();
13    return "success";
14}
15