Optional package for Laravel to generate social share links.

Overview

Laravel Share

Latest Version on Packagist Software License Build Status SensioLabsInsight Total Downloads

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

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

// config/app.php
'providers' => [
    Jorenvh\Share\Providers\ShareServiceProvider::class,
];

And optionally add the facade in config/app.php

// config/app.php
'aliases' => [
    'Share' => Jorenvh\Share\ShareFacade::class,
];

Publish the package config & resource files.

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

You might need to republish the config file when updating to a newer version of Laravel Share

This will publish the laravel-share.php config file to your config folder, share.js in public/js/ and laravel-share.php in your resources/lang/vendor/en/ folder.

Fontawesome

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

Laravel share supports Font Awesome v5. For Font Awsome 4 support use version 3 of this package.

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();

This will generate the following html

<div id="social-links">
	<ul>
		<li><a href="https://www.facebook.com/sharer/sharer.php?u=http://jorenvanhocht.be" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li>
		<li><a href="https://twitter.com/intent/tweet?text=my share text&amp;url=http://jorenvanhocht.be" class="social-button " id=""><span class="fa fa-twitter"></span></a></li>
		<li><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://jorenvanhocht.be&amp;title=my share text&amp;summary=dit is de linkedin summary" class="social-button " id=""><span class="fa fa-linkedin"></span></a></li>
		<li><a href="https://wa.me/?text=http://jorenvanhocht.be" class="social-button " id=""><span class="fa fa-whatsapp"></span></a></li>    
	</ul>
</div>

Getting the raw links

In some cases you may only need the raw links without any html, you can get these by calling the getRawLinks method.

A single link

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

Outputs:

https://www.facebook.com/sharer/sharer.php?u=http://jorenvanhocht.be

Multiple links

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

Outputs:

[
  "facebook" => "https://www.facebook.com/sharer/sharer.php?u=http://jorenvanhocht.be",
  "twitter" => "https://twitter.com/intent/tweet?text=Share+title&url=http://jorenvanhocht.be",
  "linkedin" => "http://www.linkedin.com/shareArticle?mini=true&url=http://jorenvanhocht.be&title=Share+title&summary=Extra+linkedin+summary+can+be+passed+here",
  "whatsapp" => "https://wa.me/?text=http://jorenvanhocht.be",
]

Optional parameters

Add extra classes, id's or titles to the social buttons

You can simply add extra class(es), id('s), title(s) or relationship(s) by passing an array as the third parameter on the page method.

Share::page('http://jorenvanhocht.be', null, ['class' => 'my-class', 'id' => 'my-id', 'title' => 'my-title', 'rel' => 'nofollow noopener noreferrer'])
    ->facebook();

Which will result in the following html

<div id="social-links">
	<ul>
		<li><a href="https://www.facebook.com/sharer/sharer.php?u=http://jorenvanhocht.be" class="social-button my-class" id="my-id" rel="nofollow noopener noreferrer"><span class="fa fa-facebook-official"></span></a></li>
	</ul>
</div>

Custom wrapping

By default social links will be wrapped in the following html

<div id="social-links">
	<ul>
		<!-- social links will be added here -->
	</ul>
</div>

This can be customised by passing the prefix & suffix as a parameter.

Share::page('http://jorenvanhocht.be', null, [], '<ul>', '</ul>')
            ->facebook();

This will output the following html.

<ul>
	<li><a href="https://www.facebook.com/sharer/sharer.php?u=http://jorenvanhocht.be" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li>
</ul>

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Not working with me??

    Not working with me??

    I did everything like described in the doc but not working in the end it shows only

    <div id="social-links"><ul>laravel-share::laravel-share-fa4.facebooklaravel-share::laravel-share-fa4.twitterlaravel-share::laravel-share-fa4.gpluslaravel-share::laravel-share-fa4.linkedin</ul></div>

    opened by johnef 18
  • Implements a method that returns only the built link of the social network

    Implements a method that returns only the built link of the social network

    This PR implements a method that returns only the built link of the Social Network

    In case of using combined it return an array containing all the link of the social networks called

    @jorenvh

    opened by samuelhgf 7
  • buttons isnt' works

    buttons isnt' works

    Hi, i was do all steps. {{!! Share::page('http://jorenvanhocht.be')->facebook(); !!}}

    return:

    <div id="social-links"><ul>laravel-share::laravel-share-fa4.facebook</ul></div>

    opened by Heqma 6
  • Laravle-share using

    Laravle-share using

    Hello,  I have some troubles implementing laravel-share. I try using this code: Share::currentPage()->facebook();

    but I'm not sure how and where use it, if I using in controller just pass a var? or I need to use directly in view? when I use like:

    <span class="post_share">{{ Share::currentPage()->facebook() }}</span> but show this:

    <div id="social-links"><ul>laravel-share::laravel-share-fa4.facebook</ul></div> thankyou for your help

    opened by dannylank 5
  • Remove the Arr dependency

    Remove the Arr dependency

    It removes the Arr helper dependency and decouples it a little bit. I don't see any reason to have this dependency here.

    Btw, I think that this check for one element on an array in getRawLinks() method (and then returning its string representation) is kind of clumsy, because it increases complexity on the client side. As a client, I have to check the return type before making a decision. I would prefer to get an array all the time and deal with only one type.

    opened by kudashevs 4
  • Whatsapp URL Should be URLEncoded

    Whatsapp URL Should be URLEncoded

    Now whatsapp It's giving an error "This link couldn´t be opened. Check the link and try again." This is because the url now needs to be URLEncoded .

    opened by victoryoalli 4
  • Non-static method Jorenvh\Share\Share::currentPage() should not be called statically

    Non-static method Jorenvh\Share\Share::currentPage() should not be called statically

    According to the README.md, we have to use it like that, but it leads to this error: Non-static method Jorenvh\Share\Share::currentPage() should not be called statically. As it says, it is caused by using page or currentPage method statically on Share class, but the page method is not defined statically. I think this can be resolved by changing those methods statically. Like this:

    public static function page(...)
    {
    ...
    }
    

    Or alternatively, using the ShareFacade instead.

    P.S: I have followed the installation and the alias is defined.

    opened by majidalaeinia 4
  • facebook error

    facebook error "href should represent a valid URL" and twitter not showing url at all only error only when server live

    Thats odd! I have this code in my blade file: <col-xs-3><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u={{url()->current()}}" class="social-button " id=""><span class="fa fa-facebook-official fa-3x"></span></a></col-xs-3> <div class="col-xs-3"><a target="_blank" href="https://twitter.com/intent/tweet?text=Nea Karvali Kavalas&amp;url={{url()->current()}}" class="social-button " id=""><span class="fa fa-twitter fa-3x"></span></a> </div> <div class="col-xs-3"><a target="_blank" href="https://plus.google.com/share?url={{url()->current()}}" class="social-button " id=""><span class="fa fa-google-plus fa-3x"></span></a></div> <div class="col-xs-3"><a target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url={{url()->current()}}" class="social-button " id=""><span class="fa fa-linkedin fa-3x"></span></a></div>

    localhost works fine as expected but when i upload the blade file into live server it gives me facebook error "href should represent a valid URL" and sharing in twitter it navigates to share view but not including any url at all. Google + and linkeed works as expected

    desktop screensphot

    desktop screenshot

    opened by jordantsap 4
  • adding the copy link functionality

    adding the copy link functionality

    this patch will add a copy link functionality to show the link in a box and also if the user clicks on it the link will be copied to his/her clipboard. I added a new copylink.js which is needed if the developer wants to use the copy to clipboard capabilities it will result in this: copylink

    opened by reza-kharestani 3
  • Test with all PHP Versions

    Test with all PHP Versions

    This is based on the work of #24

    In order to achieve this, I had to upgrade phpunit to 6.5 and orchestra/testbench to 3.5. Most likely will this will mean that the package will be unsupported on applications based on Laravel 5.4 and lower and on PHP 5.6

    opened by sandervankasteel 3
  • Facebook share issue

    Facebook share issue

    Sharing a blog post works well with Twitter, LinkedIn, but Facebook shows the html tags of the first sentence in the share preview window. Is it a FB problem, or maybe you can "strip tags" shared content? Like (pseudo example):

    This is the lead text...

    opened by subdesign 3
  • Not working while sharing on linkedin.

    Not working while sharing on linkedin.

    I am sharing to linkedin directly by the url (http://www.linkedin.com/shareArticle?mini=true&url={{ route("candidate.test.perform", $test->slug) }}), but it shows something went wrong on the linkedin, and when i use Share::page('route')->linkedin() it throws error which says page is not static method and i cannot call it statically, after that i tried another way, i made object of share class and then call page function but it shows blank page, can anyone help ??

    $share = new \Jorenvh\Share\Share(); $share->page(route("candidate.test.perform", 123))->linkedin();

    Above code is also not working.
    
    opened by Hashir12 0
  • icons share cant show

    icons share cant show

    help, i've followed the instructions, but the icon wont appear..

    BLADE <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" /> <div class="social-btn-sp"> {!! $shareButtons !!} </div>

    CONTROLLER $shareButtons = \Share::page( 'https://keerom-bapelitbangda.com/' ) ->facebook() ->twitter() ->linkedin() ->telegram() ->whatsapp() ->reddit(); return

    laravel-share::laravel-share-fa5.facebooklaravel-share::laravel-share-fa5.twitterlaravel-share::laravel-share-fa5.linkedinlaravel-share::laravel-share-fa5.telegramlaravel-share::laravel-share-fa5.whatsapplaravel-share::laravel-share-fa5.reddit

    Pls Help me..

    opened by gusvinandaellya 0
  • getRawLinks() function working with linkedin, twitter, whatsapp, instagram.

    getRawLinks() function working with linkedin, twitter, whatsapp, instagram.

    ERROR htmlspecialchars(): Argument #1 ($string) must be of type string, array given

    When using the getRawLinks() function with linkedin, twitter, instagram and other it pops up with the error above, please help.

    Though its working fine with facebook.

    opened by techibaba 1
Releases(4.2.0)
Owner
Joren Van Hocht
PHP developer with a passion for Laravel
Joren Van Hocht
Arc social share - A Social Bookmarking Plugin for Textpattern

arc_social_share A Social Bookmarking Plugin for Textpattern; easily add links for sharing content with numerous social networks. arc_social_share 1.4

Andy Carter 5 Nov 15, 2022
Private groups to share messages, photos, videos, links with friends and family.

A truly private space for you and your friends What is Zusam ? Zusam (/tsuˈzam/) is a free and open-source way to self-host private forums for groups

Zusam 104 Dec 20, 2022
A simple helper to generate and display pagination navigation links

Intro to CHocoCode Paginator Friendly PHP paginator to paginate everything This package introduces a different way of pagination handling. You can rea

faso-dev 3 Aug 24, 2021
Talkino allows you to integrate multi social messengers and contact into your website and enable your users to contact you using multi social messengers' accounts.

Talkino Welcome to our GitHub Repository Talkino is a click to chat plugin to show your agents’ multiple social messengers, phone and emails on the ch

Traxconn 2 Sep 21, 2022
This library uses GD and EXIF (optional) PHP extensions so make sure you have them installed.

simple and fast image processing class that can downscale, compress and convert images using php-gd native functions

Leon 8 Jul 15, 2022
Fully covered with tests, documented by Swagger and dockerized API based on enterprise-level framework with optional queue worker.

symfony-api Fully covered with tests, documented by Swagger and dockerized API based on enterprise-level framework with optional queue worker. ⚙️ Depl

Oleksii Velychko 1 Nov 20, 2022
This repository includes direct links to Genshin Impact updates

GenshinRepository This repository includes direct links to Genshin Impact updates, with this, it allows you to download Genshin Impact updates without

Rifqi Arief 72 Jan 3, 2023
OctoLinker — Links together, what belongs together

What is OctoLinker? OctoLinker is a browser extension for GitHub, that turns language-specific statements like include require or import into links. I

OctoLinker 5.1k Jan 5, 2023
Buy and sell crypto top 100 crypto with our fake currency. Donate to and use our referal links for discounts

PLEASE ENABLE SQLITE3 AND GD OR GD2 IN XAMPP TO RUN THE APP! (SEE HOW_TO_SETUP_XAMPP.gif) ![alt text](https://github.com/Tby23rd/Project1-Cryptosimul

Tabitha Maru 0 Dec 26, 2021
This composer plugin is a temporary implementation of using symbolic links to local packages as dependencies to allow a parallel work process

Composer symlinker A Composer plugin to install packages as local symbolic links. This plugin is a temporary implementation of using symbolic links to

Pierre Cassat 18 Nov 9, 2021
Sample application to bookmark links, where interface build with Angular.js + Twitter Bootstrap and server powered by PHP with Slim Framework

RESTful Bookmarks PHP Slim TODO: review and update FrontEnd Sample application to bookmark links, where interface build with Angular.js + Twitter Boot

Erko Bridee 50 Dec 15, 2021
The WebLink component manages links between resources

The WebLink component manages links between resources. It is particularly useful to advise clients to preload and prefetch documents through HTTP and HTTP/2 pushes.

Symfony 1.3k Dec 22, 2022
This extension links MediaWiki to phpBB's user table for authentication, and disallows the creation of new accounts in MediaWiki.

This extension links MediaWiki to phpBB's user table for authentication, and disallows the creation of new accounts in MediaWiki. Users must then log in to the wiki with their phpBB account.

Digitalroot Technologies 22 Feb 8, 2022
Addon for Cockpit CMS - store thumbnails and meta data for video links

VideoLinkField Addon for Cockpit CMS Copy a url from YouTube or Vimeo, click the Button "Find Values", wait a second and in the background starts a se

Raffael 3 Oct 2, 2022
Share value objects that contain the same primitive value as a singleton

sharable-value-objects Share value objects that contain the same primitive value as a singleton. Singletons are kept under WeakReference objects. Inst

mpyw 5 Nov 14, 2021
Super simple share buttons for WordPress. No images, no css, no javascript

Developer Share Buttons A super lightweight social sharing solution using either the Web Share API or simple sharing links. Description A simple, cust

Grant Richmond 28 Nov 13, 2022
📦 An easy way to share the data from your backend to the JavaScript.

Laravel Shared Data ✨ Introduction Laravel Shared Data provides an easy way to share the data from your backend to the JavaScript. ?? Quick start Inst

Coderello 326 Nov 30, 2022
Share content between your websites.

Distributor Distributor is a WordPress plugin that makes it easy to distribute and reuse content across your websites — whether in a single multisite

10up 504 Jan 3, 2023
This composer plugin allows you to share your selected packages between your projects by creating symlinks

Composer - Shared Package Plugin This composer plugin allows you to share your selected packages between your projects by creating symlinks. All share

L'Etudiant 169 Sep 20, 2022