Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ethar's avatar
Level 5

Laravel 11 aliases

i want to add to add SEOtools package to Laravel 11

composer require artesaos/seotools

but when I must put aliases, in laravel 10 put in config/app.php

    'aliases' => [
        'SEOMeta'       => Artesaos\SEOTools\Facades\SEOMeta::class,
        'OpenGraph'     => Artesaos\SEOTools\Facades\OpenGraph::class,
        'Twitter'       => Artesaos\SEOTools\Facades\TwitterCard::class,
        'JsonLd'        => Artesaos\SEOTools\Facades\JsonLd::class,
        'JsonLdMulti'   => Artesaos\SEOTools\Facades\JsonLdMulti::class,
        // or
        'SEO' => Artesaos\SEOTools\Facades\SEOTools::class,
        // ...
    ],

but aliases not exist in laravel 11

0 likes
2 replies
LaryAI's avatar
Level 58

In Laravel 11, the concept of aliases in the config/app.php file has been deprecated in favor of using class-based syntax directly within your code. This change encourages better practices for dependency management and code clarity. However, you can still use the facades provided by the SEOTools package; you just need to import them directly where you need them instead of defining aliases in the config file.

Here’s how you can adapt to this change:

  1. Install the SEOTools package: You've already added the package using Composer, which is correct:

    composer require artesaos/seotools
    
  2. Publish the configuration file (if you haven't already):

    php artisan vendor:publish --provider="Artesaos\SEOTools\Providers\SEOToolsServiceProvider"
    
  3. Use the Facades in your code: Instead of setting aliases in the config/app.php, directly use the namespaces in your files where you need to use SEOTools. For example, in a controller, you would do the following:

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use Artesaos\SEOTools\Facades\SEOMeta;
    use Artesaos\SEOTools\Facades\OpenGraph;
    use Artesaos\SEOTools\Facades\TwitterCard;
    use Artesaos\SEOTools\Facades\JsonLd;
    use Artesaos\SEOTools\Facades\JsonLdMulti;
    use Artesaos\SEOTools\Facades\SEOTools;
    
    class MyController extends Controller
    {
        public function myMethod()
        {
            SEOMeta::setTitle('Home');
            OpenGraph::setDescription('This is my page description');
            TwitterCard::setUrl('http://www.url.com');
            JsonLd::setType('Product');
            // More SEO settings...
        }
    }
    
  4. Adjust your usage as needed: Anywhere in your application where you need to use SEOTools, just import the necessary classes at the top of your PHP file as shown above.

This approach keeps your code cleaner and makes it clearer at the point of use which classes are being referred to, enhancing maintainability and reducing potential conflicts that can arise from global aliases.

Please or to participate in this conversation.