ezitisitis / laravel-open-graph
Setting Open Graph for Laravel.
Fund package maintenance!
Patreon
Installs: 1 457
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
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
Setting Open Graph for Laravel.
Install
Via Composer install:
composer require ezitisitis/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 Ezitisitis\LaravelOpenGraph\Facades\OpenGraph; class HomeController extends Controller { public function index() { OpenGraph::start() ->setTitle() ->setDescription('The site description...') ->setImage(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 Ezitisitis\LaravelOpenGraph\Facades\OpenGraph; class ArticleController extends Controller { public function show(Article $article) { OpenGraph::start() ->setType('article') ->setTitle($article->title) ->setDescription($article->description) ->setImage($article->thumbnail) ->setData([ 'article:published_time' => $article->created_at->toIso8601String(), ]); return view('home'); } }