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:
Install the SEOTools package:
You've already added the package using Composer, which is correct:
composer require artesaos/seotools
Publish the configuration file (if you haven't already):
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...
}
}
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.