avassilenko / canonical-hreflang by crumby

Automatic canonical and hreflang output for Laravel 5.4
35
0
0
Package Data
Maintainer Username: crumby
Maintainer Contact: avassilenko2@gmail.com (Andrei Vassilenko)
Package Create Date: 2017-08-14
Package Last Update: 2017-09-24
Language: PHP
License: MIT License
Last Refreshed: 2024-11-08 03:00:57
Package Statistics
Total Downloads: 35
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 0
Total Forks: 0
Total Open Issues: 0

Installation:

> composer require crumby/canonical-hreflang
> php artisan vendor:publish --provider="Crumby\CanonicalHreflang\CanonicalHreflangServiceProvider" --tag=config

Register service and facade:

File: config/app.php

'providers' => [
    ......................
    'Crumby\CanonicalHreflang\CanonicalHreflangServiceProvider',
    ........................
 ];
 
 'aliases' => [ 
    ......................
    'Canonicalhreflang' => 'Crumby\CanonicalHreflang\Facades\CanonicalHreflang',
    ......................
 ];

Register global middlewear:

file app/Http/Kernel.php

protected $middleware = [
        .............................
        \Crumby\CanonicalHreflang\Middleware\CanonicalHreflangMiddleware::class
    ];

Configuration:

Besides automatically set canonical url links to head, it also sets Hreflang, if unabled. config/canonical-hreflang.php

    'multilangular' => true

Example:

  • add middleware to constructor of your controller

        class StaticPagesController extends Controller {
            public function __construct()
            {
                ...........................
                $this->middleware('CanonicalHreflang');
                ...........................
            }
        }
    
  • place this variable to your Blade template head section

    {!! $CanonicalHreflang !!} 
    
    

Documentation:

API documentation