laravel-opengraph-markup maintained by m2collective
OpenGraph Markup
A package for adding and editing OpenGraph markup on a website.
Installation
You can install the package via composer:
composer require m2collective/laravel-opengraph-markup
The package will automatically register itself.
Commands
Publishing the configuration file:
php artisan m2collective:opengraph-markup:publish-config
Publishing HTML views:
php artisan m2collective:opengraph-markup:publish-views
Usage
After installing the package, you can add and edit OpenGraph markup on your website.
Dependency injection
An example of using a package with the dependency injection:
use M2Collective\OpengraphMarkup\OpengraphMarkup;
final class Example
{
/**
* @var OpengraphMarkup
*/
protected OpengraphMarkup $markup;
/**
* @param OpengraphMarkup $markup
*/
public function __construct(
OpengraphMarkup $markup
) {
$this->markup = $markup
}
/**
* @return array
*/
public function markup(): array
{
// Editing service variables.
$this->markup
->sitename('Example')
->title('Document title')
->description('Document description')
->locale('en_GB')
->type('website')
->url('https://example.com/')
// Passing variables from the service.
return [
'sitename' => $markup->sitename->getContent(),
'title' => $markup->title->getContent(),
'description' => $markup->description->getContent(),
'locale' => $markup->locale->getContent(),
'type' => $markup->type->getContent(),
'url' => $markup->url->getContent(),
];
}
}
Facades
An example of using a package with the facades:
use M2Collective\OpengraphMarkup\Facades\OpengraphMarkup;
final class Example
{
/**
* @return array
*/
public function markup(): array
{
// Editing service variables.
$markup = OpengraphMarkup::sitename('Example')
->title('Document title')
->description('Document description')
->locale('en_GB')
->type('website')
->url('https://example.com/')
// Passing variables from the service.
return [
'sitename' => $markup->sitename->getContent(),
'title' => $markup->title->getContent(),
'description' => $markup->description->getContent(),
'locale' => $markup->locale->getContent(),
'type' => $markup->type->getContent(),
'url' => $markup->url->getContent(),
];
}
}
Blade
An example of using a package with the blade:
<!DOCTYPE html>
<html lang="en">
<head>
<x-opengraph-markup::sitename/>
<x-opengraph-markup::title/>
<x-opengraph-markup::description/>
<x-opengraph-markup::locale/>
<x-opengraph-markup::type/>
<x-opengraph-markup::url/>
</head>
<body>
</body>
</html>
License
The MIT License (MIT). Please see the License file for more information.