PHP code example of ycs77 / laravel-open-graph
1. Go to this page and download the library: Download ycs77/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/ */
ycs77 / laravel-open-graph example snippets
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');
}
}
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');
}
}