reaz's avatar
Level 5

Setting up seo control for simple Laravel site

I have setup a simple marketing site for a non profit org with Laravel. Its a simple site with 3/4 of pages, with one page for recent event. The view files are plain blade. Since i did not wanted it to be totally static, i have setup a filament backend , where they can update some of the text, page heading. So i don't have hard code them. Now they have another person, who is willing to help with the seo of the page. I am not that good with seo, so i have very little idea about what needs to set up. How do i give access to this seo person, so he can set up seo on the page. Do i setup some variable to be injected into the header, and those can be filled up from Filament backend. Anyone have any advice?

1 like
2 replies
LaryAI's avatar
Level 58

To set up SEO control for your Laravel site and allow an SEO specialist to manage it, you can follow these steps:

  1. Meta Tags Management: Create a system where meta tags (like title, description, keywords) can be dynamically managed through your Filament backend. This will allow the SEO person to update these values without touching the code.

  2. Database Setup: Create a table in your database to store SEO-related data for each page. This table might include columns like page_name, meta_title, meta_description, meta_keywords, etc.

  3. Model and Migration: Create a model and migration for the SEO data. Here's an example:

    // Migration
    Schema::create('seo_data', function (Blueprint $table) {
        $table->id();
        $table->string('page_name')->unique();
        $table->string('meta_title')->nullable();
        $table->text('meta_description')->nullable();
        $table->string('meta_keywords')->nullable();
        $table->timestamps();
    });
    
    // Model
    class SeoData extends Model
    {
        protected $fillable = ['page_name', 'meta_title', 'meta_description', 'meta_keywords'];
    }
    
  4. Filament Resource: Create a Filament resource to manage the SEO data. This will provide a user interface for the SEO person to update the meta tags.

  5. Blade Template: In your Blade templates, inject the SEO data into the <head> section. You can do this by fetching the SEO data based on the current route or page name. For example:

    @php
        $seoData = \App\Models\SeoData::where('page_name', Route::currentRouteName())->first();
    @endphp
    
    <title>{{ $seoData->meta_title ?? 'Default Title' }}</title>
    <meta name="description" content="{{ $seoData->meta_description ?? 'Default Description' }}">
    <meta name="keywords" content="{{ $seoData->meta_keywords ?? 'Default Keywords' }}">
    
  6. Route Naming: Ensure that your routes are named appropriately so that you can easily fetch the corresponding SEO data.

  7. Access Control: Use Filament's built-in authentication and authorization features to ensure that only authorized users (like the SEO person) can access and modify the SEO data.

By following these steps, you can provide a flexible and secure way for the SEO specialist to manage the SEO aspects of your site through the Filament backend.

tykus's avatar

It is pretty trivial to implement this in Filament using the SEO Filament package which provides a backend for the associated Laravel SEO package which will render the SEO meta tags on the user-facing website.

Please or to participate in this conversation.