Why Add Social Media Share Buttons in Laravel 11?

              Integrating social share buttons isn't just a nice-to-have feature—it's a proven growth strategy for modern web applications. Social signals remain a key factor in content distribution and SEO. When users share your Laravel blog posts or product pages, it creates natural backlinks, increases referral traffic, and improves domain authority over time. Platforms like Facebook and X amplify reach exponentially: one share can lead to dozens or hundreds of views from friends, followers, and groups.

For developers building with Laravel 11, adding this feature enhances user experience (UX) significantly. Visitors stay engaged longer when sharing is frictionless—no need to copy URLs manually or switch apps. Mobile users especially benefit from native integrations (e.g., WhatsApp direct sharing or Telegram instant forwarding). From a business perspective, higher share rates correlate with better conversion funnels, newsletter sign-ups, and brand awareness. Best of all, it's lightweight: no heavy JavaScript libraries required, keeping your site fast and performant. In 2026, with social algorithms still favoring shared content, implementing share buttons in Laravel is one of the highest-ROI improvements you can make to any project.



How to Add Social Media Share Buttons in Laravel 11 – Step-by-Step Tutorial

Table Of Content

1 Prerequisites

  • PHP >= 8.2
  • Composer installed
  • MySQL or another database (for the demo posts table)
  • Basic knowledge of Laravel routing, migrations, and Blade templates

2 Introduction

This comprehensive Laravel 11 tutorial shows you exactly how to implement clean, customizable social sharing functionality using the lightweight and reliable jorenvanhocht/laravel-share package. The solution requires minimal setup, works seamlessly in Blade templates, and is fully compatible with Laravel 12 as well. By the end, you'll have dynamic, per-post share buttons that open native share dialogs—boosting shares, backlinks, and overall visibility.

3 Create / Install a Laravel Project

3.1 Install Laravel Project

First, make sure your computer has a composer.
Use the following command to install new Laravel Project.

composer create-project laravel/laravel laravel11-social-share-app

Then, navigate to your project directory:

cd laravel11-social-share-app

Note: This tutorial is compatible with Laravel 12—simply use laravel/laravel:^12.0 if installing a new project.

3.2 Configure MySql Database

Configure your database in the .env file to store post data:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=social_share_db  # Create this database in MySQL
DB_USERNAME=root
DB_PASSWORD=

4 Install the Laravel Share Package

The core of this tutorial relies on the jorenvanhocht/laravel-share package, which provides a simple facade for generating social share links.

Run this command in your project root:

composer require jorenvanhocht/laravel-share

No further configuration is needed—no service providers to register or assets to publish. The package uses a fluent interface to chain platforms like ->facebook()->twitter().

5 Create Migration

We will create a migration for the posts table using the following command:

    php artisan make:migration create_posts_table

The migration file can be found at database/migrations/. Update the file to create the posts table:
    
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->text('description');
            $table->string('image')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('posts');
    }
};

Run the migration:

php artisan migrate

6 Create Model

After creating the posts table, create a Post model at app/Models/Post.php:
    
<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasFactory;
    protected $fillable = [
        'name',
        'slug',
        'description',
        'image'
    ];
}



7 Create Factory Class

We will generate dummy data using a factory class:

php artisan make:factory PostFactory --model=Post

Update the database/factories/PostFactory.php file:
    
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post>
 */
class PostFactory extends Factory
{
    public function definition(): array
    {
        $name = $this->faker->sentence();
        return [
            'name' => $name,
            'slug' => Str::slug($name),
            'description' => $this->faker->paragraph(),
            'image' => $this->faker->imageUrl(800, 600),
        ];
    }
}

Generate dummy data:

php artisan tinker

In tinker:

\App\Models\Post::factory()->count(100)->create();
Exit tinker with exit.

8 Create Controller (SocialShareButtonsController)

Create a controller to handle Integrating of Social Share Buttons :

php artisan make:controller SocialShareButtonsController

Add the following code to SocialShareButtonsController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Post;

class SocialShareButtonsController extends Controller
{
    public function index()
    {
        // Global share buttons for the page
        $shareButtons = \Share::page(url()->current(), 'Check out this awesome content!')
            ->facebook()
            ->twitter()
            ->linkedin()
            ->telegram()
            ->whatsapp()
            ->reddit();

        $posts = Post::paginate(9); // Paginate for better UX in real apps

        return view('socialshare', compact('shareButtons', 'posts'));
    }
}
?>

Note: We use url()->current() for dynamic URLs, improving share accuracy and SEO.

9 Create view Blade File

Create a socialshare.blade.php view file in the resources/views directory:
    
    <!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Social Media Share Buttons Integration in Laravel 11 || getsamplecode.com</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
        <style>
            .social-btn #social-links {
                margin: 0 auto;
            }
            .social-btn
            {
                text-align:center
            }
            .social-btn #social-links ul li 
            {
                display: inline-block;
            }          
            .social-btn #social-links ul li a {
                padding: 15px;
                border: 1px solid #ccc;
                margin: 1px;
                font-size: 30px;
            }
             #social-links{
                display: inline-table;
            }
             #social-links ul li{
                display: inline;
            }
             #social-links ul li a{
                padding: 5px;
                border: 1px solid #ccc;
                margin: 1px;
                font-size: 15px;
                background: #e3e3ea;
            }
        </style>
    </head>
    <body>
        <div class="container mt-4">
            <h2 class="mb-5 text-center">Social Media Share Buttons Laravel 11 - https://getsamplecode.com</h2>
            <div class="social-btn">
                {!! $shareButtons !!}
            </div>
<h1>List Of Posts</h1>
  <hr />
           <div class="row">
                @foreach($posts as $post)
                <div class="col-sm-4 mb-3 product-box">
                            <img src="{!! $post->image !!}" class="card-img-top" alt="{{ $post->name }}" />
                            <div class="card">
                                <div class="card-body">
                                    <h5 class="card-title">{{ $post->id }}  {{ $post->name }}</h5>
                                    <p class="card-text">{!! $post->description !!}</p>
                                    <p>{!! Share::page(url('/post/'. $post->slug))->facebook()->twitter()->whatsapp() !!}</p>
                                </div>
                            </div>
                        </div>
                @endforeach
        </div>
        </div>
    </body>
</html>
   

10 Define Routes

Open routes/web.php and add the following code:

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\SocialShareButtonsController;

Route::get('/', function () {
    return view('welcome');
});
Route::get('social-share', [SocialShareButtonsController::class, 'index']);

11 Folder Structure

12 Run Laravel Server to Test the App

Use the following artisan command to Test the App.

php artisan serve

13 Conclusion

You've now added professional social share functionality to Laravel 11. This boosts visibility and is easy to extend (e.g., add email share, copy link).
Revathi M - PHP and CodeIgniter Developer

Written by Revathi M

PHP Developer & Technical Writer · 10+ years building web applications with CodeIgniter and Laravel

Revathi specializes in PHP backend development, authentication systems, and REST API design. She writes practical, production-tested tutorials at Get Sample Code to help developers build secure applications faster.

Frequently Asked Questions

The tutorial uses the jorenvanhocht/laravel-share package, which provides a simple facade to generate social sharing links.

Run the command: composer require jorenvanhocht/laravel-share. No additional configuration or publishing is required.

The package generates share buttons for Facebook, Twitter (X), LinkedIn, Telegram, WhatsApp, Reddit, and Viber.

Use \\Share::page(current_url(), 'Optional title')->facebook()->twitter()->linkedin()->telegram()->whatsapp()->reddit(); and pass the result to your view.

Echo the variable with {!! $shareButtons !!} or use {!! \\Share::page(url('/post/'.$post->slug), $post->name)->facebook()->twitter()->whatsapp() !!} directly in the view.

The tutorial creates a 'posts' table for demo content (with name, slug, description, image), but the share package itself does not require any database.

Yes, chain only the desired methods, e.g., ->facebook()->whatsapp()->linkedin() to include just those platforms.

No, this package generates simple share links without fetching or displaying share counts. For counts, consider adding client-side scripts from each platform.

No, the package generates direct share URLs that open in a new window or app (e.g., WhatsApp mobile). No JavaScript is needed for basic sharing.

The tutorial uses Bootstrap 5 and Font Awesome for icons. You can add custom CSS to style the generated buttons and links.