Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

IsaacBen's avatar

Facebook share

I already have the option to login through facebook, and now I would like to share images from my website to facebook. Is their any package for Laravel that you recommend?

0 likes
5 replies
Sulieman's avatar
Level 21

you don't need package , its very simple and easy to use facebook share button and there is two ways

the first one

  1. Include the JavaScript SDK on your page once, ideally right after the opening tag.
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.4&appId=241110544128";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

now insert the link that you want to share in the data-href

<div class="fb-share-button" data-href="http://YourPageLink.com" data-layout="button_count"></div>

you can read more the sdk here: https://developers.facebook.com/docs/plugins/share-button

the second way without using javascript:

its more simple and faster

<a href="https://www.facebook.com/sharer/sharer.php?u=YourPageLink.com&display=popup"> share this </a>
7 likes
azharul787's avatar

@Sulieman I have also implement that logic but average 60 or 70 percent blog image is showing when I share and 40 or 30 percent blog image is not showing, I don't understand where is my fault.

azharul787's avatar

@Vable hi , I don't understand where I did wrong,

<head>
<meta property="fb:app_id" content="*********************" />
<meta property="fb:pages" content="**********************" />
<meta property="og:type" content="article" />
<meta property="og:url" content="<?php echo 'http://news.mydomain.com/share.php?id='.$news['id'].'&dt='.$news['news_date'];?>" />
<meta property="og:site_name" content="Daily Spandan" />
<meta property="og:title" content="<?php echo $news['title'];?>" />
<meta property="og:description" content="<?php echo substr(strip_tags($news['content']),0,250);?>" />
<meta property="og:image" content="http://news.mydomain.com/uploads/news/<?php echo date('Y/n/j/',strtotime($news['news_date']));echo $news['image'] ; ?>" />
</head>
<body>
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v12.0&appId=***************&autoLogAppEvents=1" nonce="qw6k31BL"></script>
<!--------this is share bitton------------>
<div class="fb-share-button" data-href="http://news.mydomain.com/share.php?id=<?php echo $news['id'].'&dt='.$news['news_date']; ?>" data-layout="button_count" data-size="large">
	<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo 'http://news.mydomain.com/share.php?id='.$news['id'].'&dt='.$news['news_date'];?>;src=sdkpreparse" class="fb-xfbml-parse-ignore">Share</a></div>
<!-------news content bellow this line----------->
agent1's avatar

sharethis is good but what about other sites such as twitter, google ??

@Sulieman

Please or to participate in this conversation.