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('/');
}
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')