Laravel 10 How To Add Social Media Share Buttons Tutorial

Reading Time: 7 minutes

Adding social media share buttons to your Laravel 10 web application is an efficient approach to promote content and engage with a larger audience in the digital age. Users can simply share your website’s content on multiple social platforms using social media share buttons, spreading the word about your content and attracting more traffic to your site.

This tutorial will walk you through the process of adding social media share buttons to your Laravel 10 application step by step. We will look at various approaches and packages for integrating share buttons for prominent social media platforms such as Facebook, Twitter, LinkedIn, Pinterest, and others.

Read More: Unblocked Games Premium: Play Unblocked Free Games

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve


Assuming laravel already installed inside your system.

Create Database & Connect

To create a database, either we can create via Manual tool of PhpMyadmin or by means of a mysql command.

CREATE DATABASE laravel_app;

To connect database with application, Open .env file from application root. Search for DB_ and update your details.


Create Model & Migration

Open project into terminal and run this command to create model & migration file.

$ php artisan make:model Post -m

It will create two files –

  • Model – Post.php inside /app/Models folder
  • Migration file – 2023_07_30_123805_create_post_table.php inside /database/migrations folder.

Read More: Laravel 10 Migrate Specific Migration File Tutorial

Open Migration file and write this complete code into it.


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

return new class extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('posts', function (Blueprint $table) {
            $table->string("title", 120);
            $table->string("url", 225);

     * Reverse the migrations.
     * @return void
    public function down()

Open model file Post.php and write this complete code into it.


namespace App\Models;

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

class Post extends Model
    use HasFactory;

    public $timestamps = false;

Run Migration


We need to create tables inside database. Run this command to migrate migrations.

$ php artisan migrate

This command will create tables inside database.

Table: posts

Insert Dummy Data


Read More: Best Pokemon ROM Hacks 2023 Guide

You need to copy the given mysql query and run into sql tab of phpmyadmin.

-- Dumping data for table `posts`

INSERT INTO `posts` (`id`, `title`, `url`) VALUES
(1, 'Concept of Route Middleware in Laravel 9 Tutorial', ''),
(2, 'Concept of Trait in Laravel 9 Tutorial with Example', ''),
(3, 'Create Signature Pad & Save Using jQuery in Laravel 9', ''),
(4, 'File or Image Upload Using Livewire Laravel 9 Tutorial', '');

You will see something like this after this test data insertion.

Install Composer Share Package

Open project into terminal and run this command to install Share package.

$ composer require jorenvanhocht/laravel-share


Publish package

$ php artisan vendor:publish --provider="Jorenvh\Share\Providers\ShareServiceProvider"

Create Application Controller


We need to create a controller file.

$ php artisan make:controller SiteController

It will create a file SiteController.php inside /app/Http/Controllers folder.

Read More: Roblox Unblocked: The Ultimate Gaming Platform for Everyone

Open SiteController.php and write this complete code into it.


namespace App\Http\Controllers;

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

class SiteController extends Controller
    public function sharePosts()
        $shareButtons = \Share::page(
            'What you are writing, just share to world to learn!!',

        $posts = Post::get();

        return view("share-post", compact('shareButtons', 'posts'));

Create Blade Layout File

Go to /resources/views folder and create a file with name share-post.blade.php

Open share-post.blade.php and write this complete code into it.

<!DOCTYPE html>
<html lang="en">

    <title>Laravel 10 Add Social Media Share Buttons</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="" />
        #social-links li {
            display: inline-block;
            padding: 4px;
            text-align: center;
            list-style: none;



    <div class="container">
        <h3>Laravel 10 Add Social Media Share Buttons</h3>
        <div class="panel panel-primary">
            <div class="panel-heading">Laravel 10 Add Social Media Share Buttons</div>
            <div class="panel-body">
                {!! $shareButtons !!}

                <table class="table table-striped">
                        @foreach ($posts as $post)
                                    {{ $post->id }}
                                    {{ $post->title }}
                                    {!! Share::page($post->url, $post->title)->facebook()->twitter()->whatsapp() !!}



Add Route

Open web.php from /routes folder and add this route into it.

use App\Http\Controllers\SiteController;

Route::get("share-posts", [SiteController::class, "sharePosts"]);

Application Testing

Run this command into project terminal to start development server,

php artisan serve

Read More: Laravel Send Push Notification to IOS Using Firebase


We hope this article helped you to learn Laravel 10 How To Add Social Media Share Buttons Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more