PHP code example of ezitisitis / laravel-open-graph

1. Go to this page and download the library: Download ezitisitis/laravel-open-graph library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ezitisitis / laravel-open-graph example snippets




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');
    }
}



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');
    }
}