XpertPhp

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Laravel 8 Share Social Media Button Example
Laravel 8 Share Social Media Button Example

Laravel 8 Share Social Media Button Example

June 15, 2021 XpertPhp

Today, We will explain to you how to add a share social media button in laravel 8(Laravel 8 Share Social Media Button Example). here we are using the “jorenvanhocht/laravel-share” package to create Share Social Media Button Example.

So you can follow the below steps for add share social media button example in laravel 8.

Overview

Step 1: Install Laravel 8

Step 2: Setting Database Configuration

Step 3: Install Newsletter Package

Step 4: Create Controller

Step 5: Create Route

Step 6: Create Blade Files

Step 7: Run Our Laravel Application

Laravel 8 Share Social Media Button Example

Step 1: Install Laravel 8

We are going to install laravel 8, so first open the command prompt or terminal and go to xampp htdocs folder directory using the command prompt. after then run the below command.

PHP
1
composer create-project --prefer-dist laravel/laravel laravel8_share_social

Step 2: Setting Database Configuration

After the complete installation of laravel. we have to database configuration. now we will open the .env file and change the database name, username, password in the .env file. See below changes in a .env file.

PHP
1
2
3
4
5
6
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Enter_Your_Database_Name(laravel8_share_social)
DB_USERNAME=Enter_Your_Database_Username(root)
DB_PASSWORD=Enter_Your_Database_Password(root)

Step 3: Install Social Media PackageIn this step, We will install a social media package using the below command.

1
composer require jorenvanhocht/laravel-share

We will add the below aliases in the “config/app.php” file.

PHP
1
2
3
4
'aliases' => [
....
'Share' => Jorenvh\Share\ShareFacade::class,
]

following command and publish config file:

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

Step 4: Create Controller
Here below command help to create the controller.

1
php artisan make:controller ShareSocialController

app/Http/ShareSocialController.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?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 5: Create Route
Add the following route code in the “routes/web.php” file.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
use App\Http\Controllers\ShareSocialController;
 
 
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('share-social', [ShareSocialController::class,'shareSocial']);
?>

Step 6: Create Blade Files

So finally, first we will open the share-social.blade.php file and then paste the following code.
resources/views/share-social.blade.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
    <title>Laravel 8 Share Social Media Button Example</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>
    <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 Example</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 Our Laravel Application
We can start the server and run this example using the below command.

1
php artisan serve

Now we will run our example using the below Url in the browser.

1
http://127.0.0.1:8000/share-social

Read Also
Laravel 8 QR Code Generator Tutorial With Example
Laravel 8 Dynamic Dependent Dropdown Using Jquery Ajax
Laravel 8 Vue JS Owl Carousel Slider Example Tutorial

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Laravel
how to share social media links in laravel, laravel 8 example, laravel 8 tutorial, laravel share post on social media, laravel share post on social media example, laravel-share to social media tutorial, social media share buttons in laravel

Post navigation

NEXT
Laravel 8 QR Code Generator Tutorial With Example
PREVIOUS
custom checkbox and radio buttons using css

Latest Posts

  • Laravel 10 Dropzone Image Upload Example Tutorial
  • Laravel 10 Fullcalendar Example Tutorial
  • Laravel 10 Form Validation Example Tutorial
  • Laravel 10 Image Upload Example Tutorial
  • Laravel 10 Pagination Example Tutorial
  • Laravel 10 Send Email Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JQuery Interview Questions and Answers

SUBSCRIBE TO OUR NEWSLETTER

Email


Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

Sponsored Links : minifytools.com

© Copyright 2018 - © 2023, All Rights Reserved Powered by XpertPhp.com