PHP code example of fkrzski / laravel-canonical

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

    

fkrzski / laravel-canonical example snippets


use Fkrzski\LaravelCanonical\Facades\Canonical;

// Current request URI
Canonical::generate(); // https://example.com/blog/post

// Override with a custom path
Canonical::generate('/products/item'); // https://example.com/products/item

// Current request with query parameters (preserved)
// Request: /search?q=laravel&page=2
Canonical::generate(); // https://example.com/search?q=laravel&page=2

// Override path even when on different URL
// Current: /old-url, Generate: /new-canonical-url
Canonical::generate('/new-canonical-url'); // https://example.com/new-canonical-url

// config/canonical.php
return [
    'domain' => env('CANONICAL_DOMAIN', config('app.url')),
];
bash
php artisan vendor:publish --tag="canonical-config"