1
0
Fork 0

Update AvatarController

This commit is contained in:
Daniel Supernault 2019-04-06 16:45:53 -06:00
parent acd705e9d3
commit b7547a4ad4
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 29 additions and 0 deletions

View File

@ -96,4 +96,33 @@ class AvatarController extends Controller
return $avatarpath; return $avatarpath;
} }
public function deleteAvatar(Request $request)
{
$user = Auth::user();
$profile = $user->profile;
$avatar = $profile->avatar;
if($avatar->media_path == 'public/avatars/default.png' || $avatar->thumb_path == 'public/avatars/default.png') {
return;
}
if(is_file(storage_path('app/' . $avatar->media_path))) {
@unlink(storage_path('app/' . $avatar->media_path));
}
if(is_file(storage_path('app/' . $avatar->thumb_path))) {
@unlink(storage_path('app/' . $avatar->thumb_path));
}
$avatar->media_path = 'public/avatars/default.png';
$avatar->thumb_path = 'public/avatars/default.png';
$avatar->change_count = $avatar->change_count + 1;
$avatar->save();
Cache::forget('avatar:' . $avatar->profile_id);
return response()->json(200);
}
} }