PHP code example of zanysoft / laravel-meta-tags

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

    

zanysoft / laravel-meta-tags example snippets


'providers' => array(

    ZanySoft\LaravelMetaTags\MetaTagsServiceProvider::class,

)

'aliases' => array(

    'MetaTag'   => ZanySoft\LaravelMetaTags\Facades\MetaTag::class,

)

 'add_trialing_slash' => false, 

 'canonical_query_string' => false, 

{!! MetaTag::twitterCard() !!}

{!! MetaTag::openGraph() !!}

{!! MetaTag::renderAll() !!}

 

namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use MetaTag;

abstract class Controller extends BaseController 
{
    use ValidatesRequests;

    public function __construct()
    {
        // Defaults
        MetaTag::set('description', 'Blog Wes Anderson bicycle rights, occupy Shoreditch gentrify keffiyeh.');
        MetaTag::set('image', asset('images/default-share-image.png'));
    }
}

 

namespace App\Http\Controllers;

use MetaTag;

class HomeController extends Controller 
{
    public function index()
    {
        // Section description
        MetaTag::set('title', 'You are at home');
        MetaTag::set('description', 'This is my home. Enjoy!');

        return view('index');
    }

    public function detail()
    {
        // Section description
        MetaTag::set('title', 'This is a detail page');
        MetaTag::set('description', 'All about this detail page');
        MetaTag::set('image', asset('images/detail-logo.png'));

        return view('detail');
    }

    public function private()
    {
        // Section description
        MetaTag::set('title', 'Private Area');
        MetaTag::set('description', 'You shall not pass!');
        MetaTag::set('image', asset('images/locked-logo.png'));

        return view('private');
    }
}

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <title>{{ MetaTag::get('title') }}</title>

        {!! MetaTag::tag('description') !!}
        {!! MetaTag::tag('image') !!}
        
        {!! MetaTag::canonical() !!}

        {!! MetaTag::openGraph() !!}
        
        {!! MetaTag::twitterCard() !!}

        {{--Set default share picture after custom section pictures--}}
        {!! MetaTag::tag('image', asset('images/default-logo.png')) !!}
    </head>

    <body>
        @yield('content')
    </body>
</html>

$ php artisan vendor:publish --provider="ZanySoft\LaravelMetaTags\MetaTagsServiceProvider"