PHPackages                             bahmanshams/shareable-link - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bahmanshams/shareable-link

ActiveLibrary

bahmanshams/shareable-link
==========================

Conveniently generate shareable URLs for various social media websites

1.0.2(6y ago)14MITPHPPHP ^7.2

Since Jun 27Pushed 6y agoCompare

[ Source](https://github.com/bahmanshams/shareable-link)[ Packagist](https://packagist.org/packages/bahmanshams/shareable-link)[ RSS](/packages/bahmanshams-shareable-link/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (4)Used By (0)

Shareable Links
===============

[](#shareable-links)

Introduction
------------

[](#introduction)

Conveniently generate shareable URLs for a variety of different social media websites, using the syntax each uses for their own links.

Installation
------------

[](#installation)

You can install this package with Composer using the following command:

```
composer require bahmanshams/shareable-link:^1.0.0
```

Example Usage
-------------

[](#example-usage)

```
$url = new \BahmanShams\ShareableLink('http://example.com/', 'Example Site');

// Alternatively, with the helper function:
// shareable_link('http://example.com/', 'Example Site');

echo $url->facebook;
// https://www.facebook.com/dialog/share?app_id=ABC123&href=https://example.com/&display=page&title=Example+Site

echo $url->twitter;
// https://twitter.com/intent/tweet?url=https://example.com/&text=Example+Site

echo $url->whatsapp;
// https://wa.me/?text=Example+Site+https%3A%2F%2Fexample.com%2F

echo $url->linkedin;
// https://www.linkedin.com/sharing/share-offsite?url=https://example.com
```

Facebook Link Notes
-------------------

[](#facebook-link-notes)

A link shareable through Facebook requires an app ID from the platform. By default, this will attempt to be obtained through a `FACEBOOK_APP_ID` environment variable. However, if this environment variable does not exist, or you need to pass through different app IDs for different URLs, you can pass one through explicitly to the `getFacebookUrl()` method.

```
$url = new \BahmanShams\ShareableLink('http://example.com/', 'Example Site');

putenv('FACEBOOK_APP_ID=ABC123');

echo $url->facebook;
// https://www.facebook.com/dialog/share?app_id=ABC123&href=https://example.com/&display=page&title=Example+Site

echo $url->getFacebookUrl('XYZ789');
// https://www.facebook.com/dialog/share?app_id=XYZ789&href=https://example.com/&display=page&title=Example+Site
```

Laravel Model Trait
-------------------

[](#laravel-model-trait)

If you're using Laravel and want to be able to use these methods directly from an Eloquent model as a convenient method, you can simply create one.

The advantage of this is that you get full control over the URL and title you want to be used while still keeping a fluent syntax.

```
class News extends Model
{
    public function getShareUrlAttribute(): \BahmanShams\ShareableLink
    {
        $url = route('news.show', $this->slug);

        return new \BahmanShams\ShareableLink($url, $this->title);
    }
}
```

You can then proceed to use the pseudo-attribute method as you would use the normal class.

```
$news->share_url->twitter;
```

Credits
-------

[](#credits)

- [Liam Hammett](https://liamhammett.com/) for the [original article](https://medium.com/@liamhammett/php-shareable-social-media-links-d859f5dd5006) that prompted this
- [Denis Smink](https://dennissmink.nl/) for the [original article](https://medium.com/@dennissmink/laravel-shareable-trait-1a6b12a05094) that prompted this

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~326 days

Total

3

Last Release

2223d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e8a14b9f997cf85aacea7d39da9dc33c38cc05fe03360578327ea9bcb25f4d9?d=identicon)[ImLiam](/maintainers/ImLiam)

![](https://www.gravatar.com/avatar/1436f98aa63da15b8367f223fce72ac921954d227795187899f9fd52c2ecb2cc?d=identicon)[bahmanshams](/maintainers/bahmanshams)

---

Top Contributors

[![imliam](https://avatars.githubusercontent.com/u/4326337?v=4)](https://github.com/imliam "imliam (4 commits)")[![bahmanshams](https://avatars.githubusercontent.com/u/10374654?v=4)](https://github.com/bahmanshams "bahmanshams (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bahmanshams-shareable-link/health.svg)

```
[![Health](https://phpackages.com/badges/bahmanshams-shareable-link/health.svg)](https://phpackages.com/packages/bahmanshams-shareable-link)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
