Skip to content

Instantly share code, notes, and snippets.

@marifuli
Created April 2, 2022 16:58
Show Gist options
  • Save marifuli/a33f258ad8dc9e5996146b34c24ccdde to your computer and use it in GitHub Desktop.
Save marifuli/a33f258ad8dc9e5996146b34c24ccdde to your computer and use it in GitHub Desktop.
Save file in Laravel
$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