Spread the love

Sharing page to facebook from a website using a link is simple as possible. In this article we will not use any package or third party tool to share the url or message to Facebook. Facebook itself provide to share URL using the SDK or a simple url share , so in this article i will show you to share page from your site to Facebook.

Facebook is most used social media app and we all want a button on our website to share the our product or contact to provider using Facebook. So in this article we will cover it in a easy way so it will not take much time to implement.

Share Page to Facebook in Laravel PHP

Share a page from a website button to Facebook

We can easily share a a page to Facebook using below url

https://www.facebook.com/sharer/sharer.php?u=https://readerstacks.com

You can use it in your html as below

<a target="_blank" href='https://www.facebook.com/sharer/sharer.php?u=https://readerstacks.com'>Share to Facebook </a>

Let’s take an example

Step 1 : Create routes

Add appropriate routes to connect our URL to controller therefore open routes/web.php and add below routes

<?php
use Illuminate\Support\Facades\Route;
use \App\Http\Controllers\PostController;


Route::get('/share-post',[PostController::class, 'share']);

Here we created one route only that means you can create it anywhere but we are using it only our demo purpose.

Step 2 : Create Controller

Now, create the controller as we have mentioned in routes is PostController and also create three methods create, store and refreshCaptcha so create a file in app\Http\Controllers\PostController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;


class PostController extends Controller
{

    public function share()
    {
        return view('post.share-post');
    }
}

Step 5 : Create view

We have create the controller and now we will create the view to show the button for sharing on social media

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Readerstacks Share/Send Message to WhatsApp in Laravel PHP </title>

    <link href="//netdna.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.1/css/all.min.css" integrity="sha512-9my9Mb2+0YO+I4PUCSwUYO7sEK21Y0STBAiFEYoWtd2VzLEZZ4QARDrZ30hdM1GlioHJ8o8cWQiy8IAb1hy/Hg==" crossorigin="anonymous" referrerpolicy="no-referrer" />


</head>


<body class="antialiased">
    <div class="container">
        <!-- main app container -->
        <div class="readersack">
            <div class="container">
                <div class="row">
                    <div class="col-md-6 offset-md-3">
                        <h3> Share Page to Facebook in Laravel PHP Angular Jquery - Readerstacks</h3>

                        <div class="row">

                            <div class="col-12">
                                
                                <a class="btn btn-danger" target="_blank" href='https://www.facebook.com/sharer/sharer.php?u=https://readerstacks.com'>Share to Facebook </a>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <!-- credits -->
        <div class="text-center">
            <p>
                <a href="#" target="_top"> Share Page to Facebook in Laravel PHP Angular Jquery React - Readerstacks</a>
            </p>
            <p>
                <a href="https://readerstacks.com" target="_top">readerstacks.com</a>
            </p>
        </div>
    </div>
</body>

</html>

Also Read : How to Share URL on social media using package in Laravel 9/8/7/6/5 ?

Leave a Reply