Laravel 11 - SEO Analyzer Tool Integration

Touseef Afridi
01 Jan 25

Laravel 11 - SEO Analyzer Tool Integration

In this tutorial, we’ll show how to integrate an SEO Analyzer Tool in Laravel 11. Learn to analyze meta tags, keywords, and page performance to boost SEO and search engine rankings.


If you're a video person, feel free to skip the post and check out the video instead!


Quick Overview

This guide demonstrates how to integrate SEO analysis into a Laravel project using the SEO-Analyzer package. To start, create a fresh Laravel project and install the package via Composer. After installation, a SeoController is created to utilize the SeoFacade for analyzing a website's SEO data. The index method in this controller retrieves valuable insights such as headers, links, images, and keywords from the specified website. By updating the route in the routes/web.php file to point to this method and running the Laravel development server, you can easily view the SEO analysis results directly in your browser. This integration allows for a simple yet powerful way to incorporate SEO insights into your Laravel application, enabling you to analyze and display SEO data such as keywords, headers, and links. This approach is particularly useful for streamlining SEO reporting and enhancing the SEO capabilities of your Laravel-based projects.

Step # 1 : Create fresh Laravel project.

To begin the integration, run the global command to create a new Laravel project named seo-analyzer. You must have Laravel installed globally to run this. Use the command.
laravel new seo-analyzer
Or
If you don't have Laravel globally installed. Use the Composer command.
composer create-project laravel/laravel --prefer-dist seo-analyzer
Upon running one of these commands, you'll be prompted with the following options.
  1. Would you like to install the starter kit? — Select none.
  2. Select the testing framework. — Choose Pest.
  3. Select the database for your application. — Choose mysql.
  4. Run the default database migration? — Select yes.

The command will create a fresh Laravel project named seo-analyzer, where the starter kit is skipped, Pest is selected as the testing framework, MySQL is chosen for the database, and default migrations are executed.

Step # 2 : Navigate to the project directory.

After creating the Laravel project, navigate to the project directory. Open a terminal (e.g., Git Bash) and change the directory to your Laravel project's root folder by running
cd c:xampp/htdocs/seo-analyzer

Step # 3 : Install the SEO-Analyzer package.

To integrate SEO analysis functionality into your Laravel project, install the seo-analyzer package, which provides various tools for analyzing SEO aspects of websites. The package simplifies the process of gathering SEO data and insights, making it easier to analyze SEO performance across various metrics. Run the following command in your terminal.
composer require madeitbelgium/seo-analyzer
This command will retrieve the SEO-Analyzer package and its dependencies from Composer and integrate them into your project. Once installed, you’ll be able to immediately start utilizing the SEO analysis features, enabling you to analyze a website's SEO data and gain insights like headers, links, images, and keywords.

Step # 4: Create a SeoController.

To begin using the SEO analysis package, you'll need to create a controller to handle the logic for analyzing websites. This controller will interact with the seo-analyzer package to gather SEO insights for a given URL. Run the following command in your terminal to generate the SeoController.
php artisan make:controller SeoController
After generating the controller, open the file SeoController.php in the app/Http/Controllers directory. Replace its contents with the following code.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use MadeITBelgium\SeoAnalyzer\SeoFacade as SEO;
class SeoController extends Controller
{
    public function index()
    {
        // Analyze the given website URL and retrieve the SEO analysis result.
        $result = SEO::analyze('https://www.lipsum.com/');
        // Display the analysis result using Laravel's dd() helper.
        dd($result);
    }
}
This controller utilizes the SeoFacade from the seo-analyzer package to analyze the SEO data of the given URL and displays the result using Laravel's dd() helper function, which helps with debugging the SEO analysis output.

Step # 5 : Update route.

To make your SEO analysis functionality accessible via a route, you'll need to update the routes file in your Laravel project. Open the routes/web.php file and import the SeoController class at the top.
use App\Http\Controllers\SeoController;
Next, update the route definition to link the URL endpoint to the index method in the SeoController. Use the following code.
Route::get('/', [SeoController::class, 'index']);
This route ensures that when you visit the root URL of your application (e.g., http://localhost:8000), the index method in the SeoController is executed. This triggers the SEO analysis and displays the result.

Step # 6 : It's time to test.

To test the SEO analysis functionality, you'll need to start the Laravel development server. Run the following command in your terminal.
php artisan serve
Once the server is up and running, navigate to the following URL in your browser.
127.0.0.1:8000

This will execute the SEO analysis and display the insights for the website you’ve set in your controller (e.g., https://www.lipsum.com/). You will be able to view details such as headers, links, images, and keywords directly from the analysis results.
To retrieve specific details such as Keywords, Headers, Links, and Images, update the index method in your SeoController to access them from the result returned by the SEO::analyze() method. Here’s how you can do it
public function index()
{
    // Analyze the given website URL for SEO details.
    $result = SEO::analyze('https://www.lipsum.com/');
    // Display specific analysis results for headers, links, images, and keywords.
    dd(
        $result['full_page']['headers'],
        $result['full_page']['links'],
        $result['full_page']['images'],
        $result['full_page']['keywords']
    );
}

Now, you should see detailed insights such as headers, links, images, and keywords, which will allow you to evaluate the SEO performance of the specified URL and make necessary adjustments based on the analysis.

Conclusion

By following this process, you can easily integrate SEO analysis functionality into your Laravel application using the SEO-Analyzer package. This package simplifies the retrieval of valuable SEO insights, including headers, links, images, and keywords, which can significantly aid in analyzing SEO performance. With this setup, you can analyze any website's SEO data and display it directly within your Laravel application. Furthermore, the solution can be expanded for more advanced SEO analysis, ensuring scalability for applications like content management systems, marketing platforms, or websites where SEO optimization is crucial. You can build more complex features on top of this foundation, such as keyword tracking, on-page SEO checks, or integrating SEO insights into user-facing dashboards. With a clear and modular setup, extending this to analyze multiple websites or adding more analysis parameters will be simple, making it a versatile and scalable solution for SEO analysis in Laravel projects.
For more details, please refer to the package documentation.
Share this with friends!


"Give this post some love and slap that 💖 button as if it owes you money! 💸😄"
0

0 Comments

To engage in commentary, kindly proceed by logging in or registering