Created
January 26, 2023 01:42
-
-
Save destroylord/166b5f257645b74808733b87d1e1ba78 to your computer and use it in GitHub Desktop.
Update Old Upload Image in Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Storage; | |
public function update(Post $post) | |
{ | |
if ( request()->file('thumbnail')) { | |
Storage::delete($post->thumbnail); | |
$thumbnail = request()->file('thumbnail')->store('images/posts' ); | |
}else{ | |
$thumbnail = $post->thumbnail; | |
} | |
$attr['thumbnail'] = $thumbnail; | |
$post->update($attr); | |
return back(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment