Created
April 2, 2022 16:58
-
-
Save marifuli/a33f258ad8dc9e5996146b34c24ccdde to your computer and use it in GitHub Desktop.
Save file 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
$file = $req->file('picture'); | |
$old = public_path($user->getAttributes()['picture']); | |
if( | |
$old && | |
is_file($old) | |
) | |
{ | |
unlink($old); | |
} | |
$name = $user->id .'-picture.' . $file->getClientOriginalExtension(); | |
$folder = 'storage/user/avatar/' ; | |
$file->move(public_path($folder), $name); | |
$user->picture = $folder . $name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment