ycs77/laravel-open-graph

This package is abandoned and no longer maintained. No replacement package was suggested.

Setting Open Graph for Laravel.

Fund package maintenance!
Patreon

v0.2.0 2022-10-14 13:01 UTC

This package is auto-updated.

Last update: 2024-06-23 20:48:35 UTC


README

Laravel Open Graph

Latest Version on Packagist Software License GitHub Tests Action Status Style CI Build Status Total Downloads

Recommended to use archtechx/laravel-seo or artesaos/seotools package instead.

Setting Open Graph for Laravel.

Install

Via Composer install:

composer require ycs77/laravel-open-graph

Include Open Graph meta view into your layout <head>:

@include('open-graph::meta')

Usage

Set Open Graph metadata into Controller (this example page title default is Laravel app name):

HomeController

<?php

namespace App\Http\Controllers;

use Ycs77\LaravelOpenGraph\Facades\OpenGraph;

class HomeController extends Controller
{
    public function index()
    {
        OpenGraph::start()
            ->title()
            ->description('The site description...')
            ->image(asset('images/og-image.png'));

        return view('home');
    }
}

Set the article's Open Graph metadata Controller (this example article title like Article name - App name):

ArticleController

<?php

namespace App\Http\Controllers;

use App\Article;
use Ycs77\LaravelOpenGraph\Facades\OpenGraph;

class ArticleController extends Controller
{
    public function show(Article $article)
    {
        OpenGraph::start()
            ->type('article')
            ->title($article->title)
            ->description($article->description)
            ->image($article->thumbnail)
            ->data([
                'article:published_time' => $article->created_at->toIso8601String(),
            ]);

        return view('home');
    }
}

Open Graph references: https://developers.facebook.com/docs/sharing/webmasters/