ycs77 / laravel-open-graph
Setting Open Graph for Laravel.
Fund package maintenance!
Patreon
Requires
- php: >=7.1.3
- illuminate/contracts: >=5.6
- illuminate/support: >=5.6
Requires (Dev)
- mockery/mockery: ^1.3.1
- phpunit/phpunit: >=7.0
README
Laravel Open Graph
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/