Join WhatsApp ChannelJoin Now

Laravel 8 Share Social Media Button

Hi Dev,

Today, i we will show you laravel 8 share social media button. This article will give you simple example of laravel 8 share social media button. you will learn laravel 8 share social media button.

In this artical i will show you laravel 8 share social media button. We can use this example in Laravel 6, Laravel 7, Laravel 8, all. So let’s follow few step to create example of laravel 8 share social media button.

Preview:
Share Social Media Button in laravel

Step 1:- Install Laravel

First of, open your terminal and install new Laravel:

composer create-project --prefer-dist laravel/laravel sharesocial

Step 2:- Connect Database .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=databse
DB_USERNAME=root
DB_PASSWORD=

Step 3:- Install Social Media Package

In this step, folllowing command and install social media button package in laravel

composer require jorenvanhocht/laravel-share

After that, visit config directory and open app.php file. And add code:
config/app.php

'aliases' => [
    'Share' => Jorenvh\Share\ShareFacade::class,
]

following command and publish config file:

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

Step 4:- Add Routes

Go to routes/web.php file and following routes in web.php file:

use App\Http\Controllers\ShareSocialController; 
 
Route::get('/share-social', [ShareSocialController::class,'shareSocial']);

Step 5:- Create Controllers

run following command and create controllers

php artisan make:controller ShareSocialController

app/http/controller\ShareSocialController.php

<?php
 
namespace App\Http\Controllers;
 
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
 
class ShareSocialController extends Controller
{
    public function shareSocial()
    {
        $socialShare = \Share::page(
            'https://codeplaners.com/',
            'Code Planers',
        )
        ->facebook()
        ->twitter()
        ->reddit()
        ->linkedin()
        ->whatsapp()
        ->telegram();
         
        return view('index', compact('socialShare'));
    }
}

Step 6:- Create Blade Views

In this step, create one blade views file. resources/views folder and create the blade view file:

Create file share-social.blade.php and add code:

<!DOCTYPE html>
<html>
<head>
    <title>Laravel 8 Share Social Media Button</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"  />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js" ></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" />
    <style type="text/css">
        li{
            list-style: none;
            background: #e2e2e2;
            margin-left: 5px;
            text-align: center;
            border-radius:5px;
        }
        li span{
            font-size: 20px;
        }
        ul li{
            display: inline-block;
            padding: 10px 10px 5px;
        }
        #social-links{
            float: left;
        }
		a.social-button {
			color: #000;
		}
    </style>
</head>
<body style="background: #8ab4e8;">
    <div class="row mt-5">
        <div class="col-md-6 offset-3">
            <div class="card">
                <div class="card-header bg-success text-white">
                    <h5>Laravel 8 Share Social Media Button</h5>
                </div>
                <div class="card-body">
                    <strong class="float-left pt-2">Social Media : </strong>
                    {!! $socialShare !!}
                </div>
            </div>
        </div>
    </div>
</body>
</html>

Step 7:- Run Development Server

php artisan serve
http://127.0.0.1:8000/share-social

Recommended Posts