PHP code example of kfoobar / laravel-meta

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

    

kfoobar / laravel-meta example snippets


'providers' => [
    '...',
    KFoobar\LaravelMeta\MetaServiceProvider::class,
];

'aliases' => [
    '...',
    'Meta'    => KFoobar\LaravelMeta\Facades\Meta::class,
];



namespace App\Http\Controllers\Posts;

use App\Http\Controllers\Controller;
use KFoobar\LaravelMeta\Facades\Meta;

class PostController extends Controller
{
...

public function index()
{
    Meta::set('title', 'Your new page title');
    Meta::set('description', 'Your new meta description');
    // or...
    Meta::setTitle('Your new page title');
    Meta::setDescription('Your new meta description');    
}

public function index()
{
    Meta::get('title', 'Default title if none is set');
    Meta::get('description', 'Default description if none is set');
    // or...
    Meta::getTitle('Default title if none is set');
    Meta::getDescription('Default description if none is set');
 }

$titleTag = Meta::tag('title');
$titleTag = Meta::tag('title', 'Default title if none is set');

if (!Meta::has('title')) {
    Meta::set('title', 'This is a fallback title');
}

@setMeta('title', 'Your new page title');
@setMeta('description', 'Your new meta description');

@getMeta('title')
@getMeta('title', 'Default title if none is set')

<title>
    @getMeta('title', 'Default title if none is set')
</title>

@getTag('title')
@getTag('title', 'Default title if none is set')

@getTag('description')
@getTag('description', 'Default description if none is set')

@hasMeta('author')
   <meta name="author" content="@meta('author')">
@endhasMeta

@getTag('description')
@getTag('keywords')
@getTag('robots', 'index, follow')
@getTag('csrf-token')

@getTag('title', 'Default title if none is set')

@hasMeta('canonical')
    @getTag('canonical')
@endhasMeta

<meta name="description" content="Lorem ipsum dolor...">
<meta name="keywords" content="lorem, ipsum, dolor">
<meta name="robots" content="index, follow">
<meta name="csrf-token" content="4ipX8A07Awf60ZUBPBfy...">

<title>Default title if none is set</title>

<link rel="canonical" href="https://example.com/this-is-a-slug">