vpominchuk / laravel-easy-share
Laravel EasyShare: Fully customized social share buttons.
Requires
- php: ^7.4|^8.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0
README
laravel-easy-share
Laravel EasyShare is a fully customized and easy to use social share buttons component.
It is as easy as count to four
1. Install
$ composer require vpominchuk/laravel-easy-share
2. Publish sample config file
$ php artisan vendor:publish --tag=easy-share-config
3. Add a component to your view.
<x-easy-share />
4. Add some CSS styles:
.easy-share { display: flex; } .easy-share li { margin-right: 1.5rem; }
and you are ready to go!
Available social networks
- Viber
- Telegram
Managing social networks
You can easily add/remove/enable/disable available social networks.
Just open config/easy-share.php
file and add any social network you like.
Configuration options
Using SVG icons
To use your own SVG icons just put content of your SVG icon file into content
key of configuration file for the necessary icon.
Using Fontawesome or other icons library
The same as with SVG, just put <i class="fa-brands fa-twitter"></i>
into content
key of the config file.
Component parameters
By default, you can use <x-easy-share />
without any attributes, it will detect current url of the page, but will not detect page title.
Custom attributes can be passed to custom template.
Using custom view (template)
To use custom template, just create a folder easy-share
under resources/views/
and put your custom template in it.
<ul class="easy-share"> @foreach($services as $name => $service) <li class="easy-share-{{$name}} {{$service['class'] ?? ''}}"> <a href="{{$service['url'] ?? '#'}}" target="_blank" title="{{$service['title']}}">{!! $service['content'] ?? '' !!}</a> </li> @endforeach </ul>
Custom attributes in <x-easy-share />
component will be passed to your custom template.
All Kebab Cased and Snake Cased attributes will be transformed to Camel Case, for example:
<x-easy-share my-first-attribute="1" my_second_attribute="2" />
will be transformed to {{$myFirstAttribute}}
and {{$mySecondAttribute}}
.
Getting share links as a PHP array
You can use EasyShare
facade to get plain PHP array of share links. Example:
use Illuminate\Support\Facades\URL; use \VPominchuk\EasyShare\Facades\EasyShare; $url = URL::current(); $easyShare = EasyShare::setUrl($url); $array = $easyShare ->setTitle($pageTitle) ->setSummary($summary) ->getServices();
There are two additional methods:
Security
If you discover any security related issues, please use the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.