Blog Detail

09

Sep
Now Generate Social Share Links Quickly with Laravel Share cover image

arrow_back Now Generate Social Share Links Quickly with Laravel Share

Share links exist on almost every page in every project, creating the code for these share links over and over again can be a pain in the ass. With Laravel Share, you can generate these links in just seconds in a way tailored for Laravel.

Available services

  • Facebook
  • Twitter
  • Linkedin
  • WhatsApp
  • Reddit
  • Telegram

Installation

You can install the package via composer:

composer require jorenvanhocht/laravel-share

Publish the package config & resource files.

php artisan vendor:publish --provider="Jorenvh\Share\Providers\ShareServiceProvider"

Fontawesome

Since this package relies on Fontawesome, you will have to require its css, js & fonts in your app. You can do that by requesting an embed code via their website or by installing it locally in your project.

Javascript

Load jquery.min.js & share.js by adding the following lines to your template files.

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script>
<script src="{{ asset('js/share.js') }}"></script>

Usage

Creating one share link

Facebook

Share::page('http://jorenvanhocht.be')->facebook();

Twitter

Share::page('http://jorenvanhocht.be', 'Your share text can be placed here')->twitter();

Reddit

Share::page('http://jorenvanhocht.be', 'Your share text can be placed here')->reddit();

Linkedin

Share::page('http://jorenvanhocht.be', 'Share title')->linkedin('Extra linkedin summary can be passed here')

Whatsapp

Share::page('http://jorenvanhocht.be')->whatsapp()

Telegram

Share::page('http://jorenvanhocht.be', 'Your share text can be placed here')->telegram();

Sharing the current URL

Instead of manually passing an url, you can opt to use the currentPage function.

Share::currentPage()->facebook();

Creating multiple share Links

If want multiple share links for (multiple) providers you can just chain the methods like this.

Share::page('http://jorenvanhocht.be', 'Share title')
	->facebook()
	->twitter()
	->linkedin('Extra linkedin summary can be passed here')
	->whatsapp();

For more details about this package and source code, Please visit here.

Published at : 09-09-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project