Laravel 8 Share Social Media Button Example
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.
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.
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.
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.
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
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