User avatar Laravel

Im using Laravel 5.2 with a societ. I can pull out user details, but the problem is that the avatar does not display correctly if I paste it on src.

Socialite returns an object in which I could use it as $facebookDetails->getAvatar(), in which a value of type is returnedhttps://graph.facebook.com/v2.6/123456789/picture?type=normal

If I repeat this value in the image src, it will look as follows.

<img src="https://graph.facebook.com/v2.6/123456789/picture?type=normal" />

This does not seem to be the actual URL of the image, because when I enter it into the browser, it redirects me to the “actual” image and displays the image.

How can I display an image in a tag imgto display the actual image?

+4
source share
1 answer

Simply select the data using the function file_get_contentsand process the extracted data.

In the 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");
+5
source

Source: https://habr.com/ru/post/1658505/


All Articles