PHP code example of m2collective / laravel-opengraph-markup
1. Go to this page and download the library: Download m2collective/laravel-opengraph-markup 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/ */
m2collective / laravel-opengraph-markup example snippets
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(),
];
}
}
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(),
];
}
}