Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Share Buttons Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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" />

Implementation Patterns

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:

  • Encode the default network list in config/share-buttons.php, then render with no arguments in the template.
  • Or centralise in a small dedicated class / Blade component that reads the config and takes just the model:
// 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.

Gotchas and Tips

  • The v7 bump is the real breaking change. Laravel 10 and 11 apps, and any CI image on PHP 8.1, cannot install this. If you are pinned to an older Laravel for other dependencies, stay on 6.x until you can move — there is nothing in v7 worth splitting your dependency tree over.
  • "Some improvements" is unspecified. The changelog body says nothing concrete. Diff 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.
  • Re-publish overrides after upgrading. If you published views or config in v6, your local copies shadow the package's. Copy the new defaults in and re-apply your customisations, or you will keep rendering v6 markup indefinitely while believing you upgraded.
  • Config cache. After editing 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.
  • Escaping. Every Blade call site needs {!! !!}. Using {{ }} renders escaped markup as visible text on the page — an easy thing to miss if you only check with assertSee on the URL.
  • Ordering and 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.
  • Icons and styling. Check whether the version you install ships inline SVG or expects published CSS assets. If it is the latter and you use Vite, the published asset path needs to be reachable from your build output.
  • Extension point: custom networks are best added by supplying your own template in config or overriding the published view for that button, rather than forking — it keeps composer update clean across future majors.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource