Building a Multi-Category Blog with Laravel: A Practical Guide

Programming Technology Web Development
August 27, 2026 31
Laravel web application displayed on a laptop with code in the background
Learn how to build a flexible multi-category blog using Laravel, including database relationships, post management, slug generation, image uploads, SEO metadata, and category filtering.

Building a Multi-Category Blog with Laravel: A Practical Guide

A well-structured blog is more than a collection of articles. As the number of posts grows, readers need an easy way to discover related content, while administrators need an efficient way to organize and manage their articles.

In this guide, we will look at how to build a multi-category blog using Laravel. The approach is suitable for personal websites, developer portfolios, company blogs, and content-driven applications.

Why Use Multiple Categories?

A blog post does not always belong to a single topic.

For example, an article about building a Laravel blog could belong to Laravel, PHP, Web Development, Database, and Tutorials at the same time.

Allowing multiple categories makes your content more flexible and improves navigation for readers.

Instead of forcing every article into a single category, a many-to-many relationship allows each post to be associated with as many relevant categories as necessary.

Designing the Database

The main blog_posts table stores information about each article, including its title, slug, content, featured image, publication status, and SEO metadata.

Categories are stored separately in the blog_categories table.

Because one post can belong to multiple categories, we use a pivot table called blog_post_category.

The relationship looks like this:

Blog Post | |--- Laravel |--- PHP |--- Web Development |--- Tutorials

The pivot table connects the post and category IDs.

Laravel's Eloquent ORM makes this relationship straightforward to work with using belongsToMany().

Creating the Eloquent Relationship

In the BlogPost model, we can define the categories relationship using belongsToMany():

public function categories() { return $this->belongsToMany( BlogCategory::class, 'blog_post_category', 'blog_post_id', 'blog_category_id' ); }

The BlogCategory model contains the inverse relationship:

public function posts() { return $this->belongsToMany( BlogPost::class, 'blog_post_category', 'blog_category_id', 'blog_post_id' ); }

Once these relationships are configured, Laravel allows us to work with categories directly from a blog post.

Saving Multiple Categories

When creating or editing a post, the administrator can select multiple categories.

For example, the form might submit:

categories[] = 1 categories[] = 3 categories[] = 5

Laravel can synchronize these relationships using the sync() method:

$post->categories()->sync( $data['categories'] ?? [] );

This is particularly useful when editing an existing article because Laravel will automatically update the pivot table to match the selected categories.

Building a Better Blog Administration System

A good administration system should make managing content simple.

The blog post form should provide fields for the title, slug, excerpt, content, featured image, categories, publication status, SEO information, and publishing date.

The administrator should also be able to mark an article as featured and control whether comments are allowed.

Keeping these settings together makes the content management process much easier.

Generating SEO-Friendly Slugs

A blog post should have a readable URL.

For example:

building-a-multi-category-blog-with-laravel

is much better than:

post?id=125

Laravel's Str::slug() helper makes it easy to generate URL-friendly slugs from post titles.

However, the application should also make sure that each slug is unique.

If another article already uses the same slug, the application can generate a variation such as:

building-a-multi-category-blog-with-laravel-1

This prevents duplicate URLs and makes individual posts easier to identify.

Handling Featured Images

Featured images can significantly improve the appearance of a blog.

Instead of storing the original uploaded image without processing it, the application can resize and optimize the image before saving it.

Intervention Image is useful for this purpose.

For example, an uploaded image can be resized to a maximum width of 1200 pixels and converted to JPEG before being stored.

This reduces unnecessary file sizes while maintaining good visual quality.

Managing Publication Status

A blog application commonly needs more than a simple published or unpublished state.

Useful statuses include:

Draft

Published

Scheduled

Archived

Draft posts are still being prepared and should not appear publicly.

Published posts are available to visitors.

Scheduled posts can be prepared in advance and published at a specified date.

Archived posts can remain in the database without appearing in the main blog listing.

This gives the administrator much better control over the content lifecycle.

Adding SEO Metadata

Each article can have its own meta title and meta description.

For example, the meta title for this article is:

Build a Multi-Category Blog with Laravel | Practical Guide

The meta description provides search engines and social platforms with a concise description of the article.

Although SEO metadata does not guarantee higher search rankings, properly structured metadata helps search engines understand the purpose and content of a page.

Conclusion

Building a multi-category blog with Laravel provides a strong foundation for a scalable content management system.

Using a many-to-many relationship allows articles to belong to multiple relevant categories without duplicating category information in the blog_posts table.

Combining this relationship with slug generation, image processing, publication statuses, SEO metadata, and a clean administration interface creates a flexible blogging platform that can grow alongside the website.

Once the basic system is working, additional features such as tags, comments, related posts, scheduled publishing, author profiles, search, and analytics can be added without having to redesign the core structure.

Contact a Web Developer & IT Specialist in Mombasa

Have a project in mind or need help bringing your ideas to life? Feel free to reach out. I’d be happy to discuss your project, answer your questions, and explore how we can work together.