Add SEO to Your Laravel Application in Minutes

Creating a wonderful Laravel application is just half the task. Getting it found by search engines is where the challenge lies. SEO in Laravel makes your application visible, popular, and enhances your position on Google. Whether you run a business website, an online shop, or a blog, optimizing your web pages is essential. It ensures your content reaches the right audience.

If you are using Laravel 12, it is quite simple to enhance your search position by implementing SEO best practice in Laravel 12. Using the Honeystone Laravel SEO package, you can easily install and handle meta tags, descriptions, and social share data without intricate setup.

For instance, assume you have a personal blog developed in Laravel. By. incorporating proper SEO meta tags Laravel can make every post look more appealing in search results and on social media websites.

When You Need SEO Solution

Each desired Laravel application that will be exposed to the public requires proper SEO implementation. Whether you are creating a blog, an e-commerce website, or a corporate site, search engines require structured information to get to know your content.


Marketing department must update meta descriptions without ever having to touch code. Your product pages need rich snippets to differentiate in search engine results. All of these needs come up in nearly every contemporary web project. Manual application involves typing the same boilerplate code over and over again, which multiplies the likelihood of mistakes and inconsistencies.

Installing Laravel SEO package

Instead of repeating same code for each page with custom methods, we will use Honeystone/laravel-seo package which provides all the SEO required functionality to generate meta tags. It provides better search engine optimization, open graph tags, Twitter share tags and much more.

Before moving forward with SEO implementation in Laravel, you need to install Laravel SEO package. Open terminal and add below composer command to install:

composer require honeystone/laravel-seo

You can publish configuration files if required. Laravel will automatically discovers it’s provider and make it’s methods working. Once installed, you can start implementing SEO to your Laravel 12 application.

Adding Basic SEO Tags for Static Pages

For static pages like Home page, About us, and Contact us, adding SEO meta tags helps search engines understand page content and improve search visibility. Using Honeystone, you can quickly set up these tags directly inside your controller or view.

For example, you have page controller which manage logic for static pages like home, about and contact us. Let’s take an example to implement this for this three pages methods.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PageController extends Controller
{
        public function home()
    {
        seo()->title('Welcome to Our Website')
             ->description('Discover our services and learn how we help businesses grow.')
             ->keywords('SEO in Laravel 12, Laravel 12 add SEO, SEO best practice in Laravel 12');

        return view('home');
    }

    public function about()
    {
        seo()->title('About Our Company')
             ->description('We build innovative digital solutions and create meaningful user experiences.')
             ->keywords('SEO meta tags Laravel, Laravel SEO, company details');

        return view('about');
    }

    public function contact()
    {
        seo()->title('Contact Us')
             ->description('Reach out to our team for project inquiries, collaborations, or support.')
             ->keywords('Laravel 12 add SEO, business contact page, SEO best practice in Laravel 12');

        return view('contact');
    }
}

Here is an basic setup of adding SEO data to static page and you can customize this title, description and meta keywords as per your requirement. Once controller setup is completed, you need to add small code into your blade file.

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>{{ config('app.name', 'Laravel') }}</title>

        {{ seo()->generate()}}
        
    </head>
    <body>
        ...
    </body>
</html>

By adding this code into blade, you can see meta tags for SEO into page source and search engines like google, yahoo will use these information to provide search results. You can implement this into layout file for applying this SEO meta tag generation for all pages. To check actual generated code you can use browser view page source features and it will show similar results.

Laravel SEO tags in page source code browser

Adding SEO Tags for Dynamic Pages like Posts

Dynamic content such as blogs, products, or listings benefit most from automated SEO generation. Honeystone’s seo() helper makes this process easy.

use App\Models\Post;

class PostController extends Controller
{
    public function show(Post $post)
    {
        seo()->title($post->title)
             ->description(Str::limit(strip_tags($post->content), 150))
             ->keywords($post->tags->pluck('name')->implode(', '));

        return view('posts.show', compact('post'));
    }
}

Here instead of manually adding content for each page you get description from content and use it for SEO purposes. However you can also allow user to take this description as input while creating post and use it here.

This setup automatically applies each post’s data to your SEO tags. If you run a news site, for example, each article gets its own unique title and description pulled from the database.

Adding Twitter and Open Graph Meta Tags

Social media previews can make your content stand out while sharing. By adding Open Graph and Twitter meta tags, your webpage links appear more engaging and descriptive on Facebook, Twitter, and LinkedIn.

Here is how you can set them using the same helper:

seo()->title($post->title)
     ->description(Str::limit(strip_tags($post->content), 150))
     ->image(asset('images/' . $post->image))
     ->twitterTitle($post->title)
     ->twitterDescription(Str::limit(strip_tags($post->content), 150))
     ->twitterImage(asset('images/' . $post->image));

seo()
    ->openGraphTitle($post->title)
    ->openGraphDescription(Str::limit(strip_tags($post->content), 150))
    ->openGraphImage(asset('images/' . $post->image))
    ->openGraphUrl(url()->current())
    ->openGraphType('article');

Now, whenever your users share a post link, social platforms automatically display the proper title, image, and summary.

You can also create a tool to preview how your Twitter and Open Graph cards will look like by following our guide Build a Twitter Card Preview Tool in PHP, making it easier to ensure your shared links always look perfect.

Conclusion

Applying SEO to Laravel is really effortless with the proper tools and strategy. You now know how to configure simple SEO tags, manage dynamic content pages, and optimize social sharing. These Laravel 12 SEO best practices will make your app perform better and receive more organic traffic.

Begin small by adding SEO tags to your root pages, then move on to dynamic content as you get familiar with the package. With proper SEO implementation into Laravel application, you website will get more organic traffic and help you rank better than your competition.