A Laravel package that makes it easy to generate sharing URLs for popular social networks. Share your content on X (Twitter), Facebook, WhatsApp, LinkedIn, Pinterest, Telegram, Email, Reddit, Bluesky, and Mastodon with just a few lines of code.
- π Generate sharing URLs for 10+ social networks
- π± Support for X, Facebook, WhatsApp, LinkedIn, Pinterest, Telegram, Email, Reddit, Bluesky, and Mastodon
- π― Simple and fluent API
- π§ Easy to integrate with your models
- βοΈ Configurable (Facebook App ID support)
- β Fully tested
- π PHP 8.1+ compatible
- ποΈ Laravel 10, 11, and 12 support
You can install the package via Composer:
composer require escuelait/laravel-social-shareablePublish the configuration file:
php artisan vendor:publish --provider="Escuelait\SocialShareable\SocialShareableServiceProvider"Or, if you only want to publish the configuration file:
php artisan vendor:publish --tag=social-shareable-configUpdate your .env file with optional Facebook App ID:
FACEBOOK_APP_ID=your_facebook_app_id_hereAdd the SocialShareable trait to your model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Escuelait\SocialShareable\SocialShareable;
class Post extends Model
{
use SocialShareable;
public $title = 'Check out this amazing post!';
public $url = 'https://example.com/posts/1';
}Generate share URLs for any social network:
$post = Post::first();
// Generate share URL for X (Twitter)
$xUrl = $post->getShareUrl('x');
// Generate share URL for Facebook
$facebookUrl = $post->getShareUrl('facebook');
// Generate share URL for WhatsApp
$whatsappUrl = $post->getShareUrl('whatsapp');
// And more...
$linkedinUrl = $post->getShareUrl('linkedin');
$pinterestUrl = $post->getShareUrl('pinterest');
$telegramUrl = $post->getShareUrl('telegram');
$redditUrl = $post->getShareUrl('reddit');
$blueskyUrl = $post->getShareUrl('bluesky');
$mastodonUrl = $post->getShareUrl('mastodon');
$emailUrl = $post->getShareUrl('email');Pass custom parameters to override defaults:
$post = Post::first();
// Custom text for X with hashtags
$xUrl = $post->getShareUrl('x', [
'text' => 'Custom message with #hashtags',
]);
// Custom URL for Facebook
$facebookUrl = $post->getShareUrl('facebook', [
'u' => 'https://custom-url.com',
]);
// Custom quote for LinkedIn
$linkedinUrl = $post->getShareUrl('linkedin', [
'title' => 'Custom title for LinkedIn',
]);The trait looks for $title and $url properties on your model. You can customize this by overriding the resolution methods:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Escuelait\SocialShareable\SocialShareable;
class Article extends Model
{
use SocialShareable;
protected function resolveShareUrl(): string
{
return route('articles.show', $this->slug);
}
protected function resolveShareTitle(): string
{
return $this->headline ?? $this->title;
}
}The package supports the following social networks:
| Network | Method | Description |
|---|---|---|
| X (Twitter) | x |
Share on X with custom text (max 120 chars) |
facebook |
Share on Facebook with quote and optional App ID | |
whatsapp |
Share via WhatsApp with title and URL | |
linkedin |
Share on LinkedIn with title | |
pinterest |
Share on Pinterest with description | |
| Telegram | telegram |
Share via Telegram with text |
email |
Share via email with subject and body | |
reddit |
Share on Reddit with title | |
| Bluesky | bluesky |
Share on Bluesky with text |
| Mastodon | mastodon |
Share on Mastodon with text |
You can also use the SocialShareableGenerator class directly without a model:
use Escuelait\SocialShareable\SocialShareableGenerator;
$generator = SocialShareableGenerator::for(
'https://example.com',
'Check this out!'
);
$xUrl = $generator->x();
$facebookUrl = $generator->facebook();
$whatsappUrl = $generator->whatsapp();You can create Blade components to generate share buttons:
<!-- resources/views/components/share-buttons.blade.php -->
<div class="share-buttons">
<a href="{{ $post->getShareUrl('x') }}" target="_blank" rel="noopener noreferrer">
Share on X
</a>
<a href="{{ $post->getShareUrl('facebook') }}" target="_blank" rel="noopener noreferrer">
Share on Facebook
</a>
<a href="{{ $post->getShareUrl('whatsapp') }}" target="_blank" rel="noopener noreferrer">
Share on WhatsApp
</a>
<a href="{{ $post->getShareUrl('linkedin') }}" target="_blank" rel="noopener noreferrer">
Share on LinkedIn
</a>
</div>Run the test suite:
composer test- PHP 8.1 or higher
- Laravel 9, 10, 11, or 12
- illuminate/support package
See the CHANGELOG for recent changes.
Contributions are welcome! Please feel free to submit a pull request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This package is open-sourced software licensed under the MIT license.
Miguel Angel Alvarez
- Email: miguel@escuela.it
- Website: escuela.it
Created by EscuelaIT