Laravel socialite Save avatar

everybody, I need to Save image name in the avatar column in the database
and save the image in public/Storage/users My Code Here Save image link in the database any help, please.

public function handleProviderCallback($service)
{
    $user = Socialite::driver($service)->user();
    $FindUser = User::where('email',$user->getEmail())->first();
        if($FindUser){
            Auth::login($FindUser);
        }
        else{
            $NewUser = new User;
            $NewUser->email = $user->getEmail();
            $NewUser->name  = $user->getName();
            $NewUser->avatar  = $user->getAvatar();
            $NewUser->password  = bcrypt(123456);
            $NewUser->save();
            Auth::login($NewUser);
        }
    return redirect('/');
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Simply fetch the data using file_get_contents function and process the retrieved data.

use File;

create a helper method to get the avatar
function getSocialAvatar($file, $path){
    $fileContents = file_get_contents($file);
    return File::put(public_path() . $path . $user->getId() . ".jpg", $fileContents);
}

replace $user->getAvatar()

with the helper method

getSocialAvatar($user->getAvatar(), 'path')


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x