chengkangzai/laravel-social-share-links

A laravel pacakge that generate social share link, thats all it does

v1.0.0 2023-01-30 05:48 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require chengkangzai/laravel-social-share-links

Usage

Generate social share link for Single Social Media

use Chengkangzai\LaravelSocialShareLinks\Enums\SocialMediaType;
use Chengkangzai\LaravelSocialShareLinks\SocialShareLinksBuilder;

$builder = new SocialShareLinksBuilder();
$link = $builder->url($url) // $url is optional, if not passed, it will use the current url
    ->facebook()
    ->build();

$facebookLink = $link[SocialMediaType::Facebook];

If you prefer to call it statically

use Chengkangzai\LaravelSocialShareLinks\Enums\SocialMediaType;
use Chengkangzai\LaravelSocialShareLinks\SocialShareLinksBuilder;

$link = SocialShareLinksBuilder::make($url) // $url is optional, if not passed, it will use the current url
    ->facebook()
    ->build();

$facebookLink = $link[SocialMediaType::Facebook];

Generate social share links for Multiple Social Media

use Chengkangzai\LaravelSocialShareLinks\Enums\SocialMediaType;
use Chengkangzai\LaravelSocialShareLinks\SocialShareLinksBuilder;

$builder = new SocialShareLinksBuilder();
$link = $builder->url($url)
    ->twitter()
    ->text('Hello World')
    ->hashtags(['laravel', 'social', 'share', 'links'])
    ->via('chengkangzai')
    ->build();

$twitterLink = $link[SocialMediaType::Twitter];

Generate social share links for multiple social media with for method

use Chengkangzai\LaravelSocialShareLinks\Enums\SocialMediaType;
use Chengkangzai\LaravelSocialShareLinks\SocialShareLinksBuilder;

$builder = new SocialShareLinksBuilder();
$links = $builder->url($url)
        ->for([
            SocialMediaType::Facebook,
            SocialMediaType::Twitter,
        ])
        ->build();

$facebookLink = $links[SocialMediaType::Facebook];
$twitterLink = $links[SocialMediaType::Twitter];

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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