kudashevs/laravel-share-buttons
Add social share buttons to any Laravel app with this package. It offers configurable button components and Blade directives for popular social networks, so you can customize links, icons, and appearance while keeping your templates clean and maintainable.
v7.0.0 is a platform-floor release: PHP 8.2+, Laravel 12+, PHPUnit 11+ (the PHPUnit bump only matters if you extend or test the package internals), with PHP 8.5 explicitly supported. There are no documented API changes, so the practical upgrade work is environmental — verify your app and CI matrix before composer update.
composer require kudashevs/laravel-share-buttons
php artisan vendor:publish --tag=share-buttons-config
# also publish views if you intend to override markup
php artisan vendor:publish --tag=share-buttons-views
The service provider is auto-discovered. First place to look is the published config file — it controls which networks are enabled by default, how links open (target/rel), and the templates used to render each button. Second is the facade, which is the fastest way to see the package working.
First use case: drop share links under a blog post.
{{-- resources/views/posts/show.blade.php --}}
{!! ShareButtons::page(route('posts.show', $post), $post->title)
->facebook()
->twitter()
->linkedin()
->reddit()
->telegram()
->generate() !!}
Note the unescaped {!! !!} — the facade returns an HTML string, not a view object. If you prefer Blade-native syntax, use the package's component instead:
<x-share-buttons :url="route('posts.show', $post)" :title="$post->title" />
Keep the template dumb, put policy in config or a view model. The chainable network methods are convenient for a one-off, but repeating that list across show.blade.php, show.blade.php for a different model, and an email template drifts fast. Two better shapes:
config/share-buttons.php, then render with no arguments in the template.// app/View/Components/ShareBar.php
public function render()
{
return view('components.share-bar', [
'url' => $this->canonical,
'title' => $this->title,
]);
}
{{-- components/share-bar.blade.php --}}
@production
{!! ShareButtons::page($url, $title)->facebook()->twitter()->linkedin()->generate() !!}
@endproduction
Be deliberate about the URL you pass. Share links are just pre-filled third-party URLs; the crawler behind them (Facebook, LinkedIn, Telegram) resolves whatever you hand it. Pass the canonical absolute URL — route() or url()->current() — never a relative path or an admin/preview URL, or you will silently share broken previews. If the page is behind auth or has query-string variants (?utm_source=...), strip them first so shares consolidate onto one URL.
Testing. Because output is a plain string, feature tests are cheap:
$this->get(route('posts.show', $post))
->assertSee('facebook.com/sharer', escape: false)
->assertSee(rawurlencode($post->title), escape: false);
escape: false matters — PHPUnit's assertions escape by default and the share URLs contain & and % sequences.
Caching. Rendered share markup is deterministic per URL+title, so it caches well with the page. The one caveat: if you cache the whole post page, changing your enabled network list requires a cache clear, not just a config change.
v6.1.1...v7.0.0 on GitHub before upgrading if you have published views or have subclassed anything — "improvements" to markup or internal classes will not show up in the release note.config/share-buttons.php run php artisan config:clear (and config:cache in deploy). A surprising number of "the button list changed but nothing happened" reports are just a stale cached config.{!! !!}. Using {{ }} renders escaped markup as visible text on the page — an easy thing to miss if you only check with assertSee on the URL.rel. Share links open third-party sites. Set rel="noopener nofollow" and target="_blank" (usually a config toggle) so you are not leaking referrer or passing link equity to share endpoints.composer update clean across future majors.How can I help you explore Laravel packages today?