Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
How to Share Page to Facebook in Laravel PHP

How to Share Page to Facebook in Laravel PHP ?

Aman Jain, March 16, 2022March 16, 2022

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.

Screenshot 2022 03 16 at 3.13.57 PM
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 ?

Related

Php Laravel Laravel 9 facebooklaravelmessagephpshare

Post navigation

Previous post
Next post

Related Posts

Php Laravel where not null query with example

How to use laravel where not null and where null query with example ?

January 18, 2022January 18, 2022

In the initial stage of laravel learning you will find many challenges to build the query like where not null and where null so in this article I will show you to create where not null and where null query using laravel eloquent. To create where not null in laravel…

Read More
Php How to Send Mail with Attachment(PDF, docs,image) in Laravel

How to Send Mail with Attachment(PDF, docs,image) in Laravel 8 /9 ?

May 10, 2022May 10, 2022

Attachment with mail is very important feature of mail by which we can attach any document with our email , for example in some scenarios we want to send the invoice to user mail or some guideline to user after registration. So in this article we will learn to use…

Read More
Php Laravel slug generator

Laravel slug generator with example

November 8, 2021November 8, 2021

In this article we are going to create slug from any input field. slug is useful search engine optimization and also from security perspective because in some case we use primary id or unique id of table to fetch the detail in page but its not recommended way to show…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • The Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version