Laravel socialite facebook avatar
Simply fetch the data using file_get_contents
function and process the retrieved data.
In Controller
use File; $fileContents = file_get_contents($user->getAvatar());File::put(public_path() . '/uploads/profile/' . $user->getId() . ".jpg", $fileContents);//To show picture $picture = public_path('uploads/profile/' . $user->getId() . ".jpg");
i'm using following code:
/** * In order to save the user's avatar * REMEMBER TO ADD "use File; use Illuminate\Support\Carbon; use DB;" TO TOP! * @param $avatar Socialite user's avatar ($user->getAvatar()) * @param $userId User's id database */public function saveImageAvatar($avatar, $userId){ $fileContents = file_get_contents($avatar); $path = public_path() . '/users/images/' . $userId . "_avatar.jpg"; File::put($path, $fileContents); DB::table('Images')->insert( ['path' => $path, 'nome' => 'avatar', 'users_id' => $userId, 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), 'updated_at' => Carbon::now()->format('Y-m-d H:i:s')]);}