Code Monkey home page Code Monkey logo

laravel-share's Introduction

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.

laravel-share's People

Contributors

easoblue avatar faustbrian avatar freekmurze avatar jorenvh avatar kudashevs avatar lemaur avatar pqrs avatar rabol avatar samuelhgf avatar sandervankasteel avatar timopaul avatar usernotnull avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-share's Issues

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

Other services

Hi,
First, thank you for this great package ! Would it be possible to add Instagram or Youtube ? If so, how can I do that?
Thanks in advance for your help.

Copy to clipboard?

Is there an option to copy the link to clipboard? If not - would be good and useful to implement it :)

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 .

Problem in sharing in WhatsApp

I have installed WhatsApp on my cell phone but when I click on WhatsApp icon I get this error
Don't have WhatsApp yet?
Download
could you help me?

No method inside the Share.php is static method + Add view count of share?

There is a problem accessing the methods statically but as soon as I checked Share.php methods are not static,

$share = new Share; 

$share->currentPage()->facebook();

Object is to be created to use the methods. Otherwise it will show the error the no static method.
I guess docs should be updated the package with static function.

Also my recommendation to add share viewcount for counting number of shares. Is there any possible way to do that?

Twitter - Debugger stop

if the console window is open and the user clicks the Twitter icon there is a 'debugger' stop

Advice needed

Can you please advise me on how i go about changing the image that is used on sharing to facebook.

I am using currentPage();

I get a blank image, Ii have tried adding facebook meta tags but the image still doesn't show.

Thanks in advance.

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...

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

Icons not displayed

Im using laravel 5.5 and installed your package and followed the instructions.

Im using this on blade with {{ Share::currentPage() ->facebook() ->twitter() ->googlePlus() ->linkedin() }}

But instead of receiving the icons i receive the html code
<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=http://localhost:8000/news/ayush-doctors-told-not-to-prescribe-allopathic-medcine" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=Default share text&url=http://localhost:8000/news/ayush-doctors-told-not-to-prescribe-allopathic-medcine" class="social-button " id=""><span class="fa fa-twitter"></span></a></li><li><a href="https://plus.google.com/share?url=http://localhost:8000/news/ayush-doctors-told-not-to-prescribe-allopathic-medcine" class="social-button " id=""><span class="fa fa-google-plus"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=http://localhost:8000/news/ayush-doctors-told-not-to-prescribe-allopathic-medcine&title=Default share text&summary=" class="social-button " id=""><span class="fa fa-linkedin"></span></a></li></ul></div>
I have added the js to the layout my site default and only language is en.

{!! Share::currentPage()
->facebook()
->twitter()
->googlePlus()
->linkedin() !!}

shows dots

I have font awesome cdn added to the layout
Any help?

Refactoring

There should be an easy way to implement custom sharable providers. Like manager/driver or macro approach.

The rendering should be done by a view.

There should be a way to get the standalone URL without surrounding HTML.

The URL patterns shouldn't be in config but in a class - in best case one per provider and not a simple concatenation to support more complex URLs. So a method should be used.

https://twitter.com/devgummibeer/status/1164250012202799106

Browser support

Full disclaimer, I have not used this library at all but it looks great so I need some more information.

I've read through the README but have not found any information about browser support. I did notice that this requires jQuery 3 so that implies IE 9+ and latest(ish) versions of other browsers.

Is jQuery 3 a strict requirement e.g. can we switch to jq 1.X (because I'm already using that version so I don't want to do noConflict unless I really have to).

Does this library itself have any browser requirements other than what jquery (and possibly fontawesone) impose?

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>

Printing laravel-share::laravel-share.facebook

Hi, i did the install with the guide.
But my outputs come
<div id="social-links"><ul>laravel-share::laravel-share.facebook</ul></div>
Yes, i know i have to use {!! !!} The thing is that laravel-share::laravel-share.facebook output.
in the blade file
{!! Share::currentPage()->facebook() !!}
I did something wrong?
Regards =)

Wrong examples in calling the methods

Hello
Thanks for this nice package.
According to the examples posted, the calling of the method is static (Share::page...)

In fact these methods aren't static so they should be called

$share = new Share();
$share->page(request()->url())->facebook()
$share->currentPage()->onlyLinks()

getbootstrap 5 list-inline Class

How i can add class in
<li>
here is my code :

{!! Share::page('http://jorenvanhocht.be', null, ['class' => 'list-inline-item', 'id' => 'my-id', 'title' => 'my-title', 'rel' => 'nofollow noopener noreferrer'], '<ul class="list-inline">', '</ul>')
                                    ->facebook(); !!}

list-inline-item class has been added on <a> tag how i can added on <li> tag

Blade statement doesn't render to html code

I create this variable on the controller:

$shareComponent = Share::page('http://jorenvanhocht.be') ->facebook() ->twitter() ->linkedin() ->reddit();

I send the $shareComponent to a view, and I tried the {!! $shareComponent !!} but instead of print it like this:

<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>

the output in the template is, literally a text:

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

And no more, it doesn't show the icons or the urls, nothing.

How can I solve this problem? Its a issue?

This is what I have in my compose.json:

"require": {
"php": "^8.0",
"biscolab/laravel-recaptcha": "^5.0",
"dbfx/laravel-strapi": "^1.0",
"doctrine/dbal": "^3.1.1",
"facade/ignition": "^2.3.6",
"fideloper/proxy": "^4.0",
"freshwork/chilean-bundle": "^2.1",
"grkamil/laravel-telegram-logging": "^1.7",
"guzzlehttp/guzzle": "^7.0.1",
"jorenvanhocht/laravel-share": "^4.1",
"laravel/framework": "^8.52.0",
"laravel/tinker": "^2.6.1",
"laravel/ui": "^3.0",
"league/flysystem-aws-s3-v3": "~1.0",
"malahierba-lab/chile-rut": "5.1.*",
"mehradsadeghi/laravel-filter-querystring": "^1.1",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.0",
"sentry/sentry-laravel": "^2.7",
"spatie/laravel-markdown": "^2.1",
"transbank/transbank-sdk": "^2.0",
"vinkla/hashids": "^9.1",
"zgabievi/promocodes": "^8.1"
},

Multiple Pages?

Is there a feature to share multiple pages at once?
For example if I bulk create some products and want to share them in one post altogether

image not showing

Hello ,
i have an ecommerce website and i'm trying to share my products in facebook using your
package however when i do share a product the thumbnail doesn't appear on facebook
it juste appears like this on facebook

Capture

how can i customize facebook icon.

Description : I am trying to add below code in my laravel app

	{!! Share::currentPage('')

->facebook()
->twitter()
->linkedin('Football4Football')
->whatsapp() !!}

its showing all social media default icon. i want to put my custom created icon image
can you gude me way how to do it ?

Error in getting share link

These html tags are included in the method response i get from Share::currentPage()->facebook();
<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=http://localhost:8000/blog/Blog-1-1497827557" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li></ul></div>

Same is happening for all providers. These tags get added within href attribute instead of just the share url.
Solution Please!

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.

Adding Pinterest

Will there be any updates for adding Pinterest? How can I add this?

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>

Suggested CSS

ul { 
  overflow: auto; 
} 
ul li { 
  list-style-type: none; float: left; 
} 
ul li a span { 
  background: #205D7A; 
  color: #fff; 
  width: 40px; 
  height: 40px; 
  border-radius: 20px; 
  font-size: 25px; 
  text-align: center; 
  margin-right: 10px; 
  padding-top: 15%; 
}

.fa-facebook-square { 
  background:#3b5998 
} 
.fa-google-plus-g { 
  background:#dd4b39 
}
.fa-twitter { 
  background:#00aced 
}

maybe someone can give a better design than this :)

Services uri not applied to url

Hi I use laravel 6 after setup, the urls not correct please see the codes:
<div id="social-links"><ul><li><a href="https://wolfegy.com/job/view/725377112" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li></ul></div>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.