Facebook share using PHP, Laravel 9 Example

How to share post in Facebook using PHP? – Sharing page to Facebook from a website using a link is simple as possible. In this post i will not use any types of the package or 3rd party tool or libs to Post the URL or message to Facebook. Facebook itself support to Post URL using the SDK or a simple URL Post, therefor in this post I will show you to Post page from your site to Facebook.

Facebook is most used social media app as well as I all want a button on our blog/website to Post the our product, article, services or contact to provider using Facebook. therefor in this post I will cover it in a easy method therefor it will not take much time to implement.

I can easily posting a a page to Facebook using below URL

Facebook share using PHP

https://www.facebook.com/postingr/postingr.php?u=https://pakainfo.com

You can use it in your html as below

Free Live Chat for Any Issue

<a target="_blank" href='https://www.facebook.com/postingr/postingr.php?u=https://pakainfo.com' rel="noopener">Post to Facebook </a>

Step 1 : Make Laravel 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\ArticleController;


Route::get('/posting-article',[ArticleController::class, 'posting']);

Here i created one route only that means you can make it anywhere but i am using it only our demo purpose.

Step 2 : Make Controller

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

<?php

namespace App\Http\Controllers;

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


class ArticleController extends Controller
{

    public function posting()
    {
        return view('article.posting-article');
    }
}

Step 3 : Make view

I have make the controller and now i will make 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>Pakainfo Post/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"/>


</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> Post Page to Facebook in Laravel PHP Angular Jquery - Pakainfo</h3>

                        <div class="row">

                            <div class="col-12">
                                
                                <a class="btn btn-danger" target="_blank" href='https://www.facebook.com/postingr/postingr.php?u=https://pakainfo.com' rel="noopener">Post to Facebook </a>
                            </div>
                        </div>

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

</html>