PHP code example of philiprehberger / laravel-seo

1. Go to this page and download the library: Download philiprehberger/laravel-seo 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/ */

    

philiprehberger / laravel-seo example snippets


use PhilipRehberger\Seo\Facades\Seo;

Seo::setTitle('My Page')
   ->setDescription('Welcome to my page.')
   ->setCanonical('https://example.com/page')
   ->setOgImage('https://example.com/og.jpg')
   ->setOgType('article')
   ->setNoindex(false);

use PhilipRehberger\Seo\Facades\Seo;
use PhilipRehberger\Seo\OgType;

Seo::setOgType(OgType::Article);
Seo::setOgType(OgType::Product);
Seo::setOgType(OgType::Video);

// Raw strings are still supported
Seo::setOgType('article');

use PhilipRehberger\Seo\SeoService;

class PageController extends Controller
{
    public function show(SeoService $seo): View
    {
        $seo->setTitle('About Us')
            ->setDescription('Learn about our team.');

        return view('about');
    }
}

Seo::forPage('home');

Seo::addJsonLd([
    '@context' => 'https://schema.org',
    '@type'    => 'Article',
    'headline' => 'My Blog Post',
]);

// Built-in schema generators
Seo::addJsonLd(Seo::getOrganizationSchema());
Seo::addJsonLd(Seo::getWebsiteSchema());
Seo::addJsonLd(Seo::getServiceSchema('Web Design', 'We design beautiful websites.', 'Design'));
Seo::addJsonLd(Seo::getBreadcrumbSchema([
    ['name' => 'Home', 'url' => 'https://example.com/'],
    ['name' => 'Blog', 'url' => 'https://example.com/blog'],
]));

Seo::reset();
bash
php artisan vendor:publish --tag=laravel-seo-config
bash
php artisan vendor:publish --tag=laravel-seo-views