NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Posts for Laravel

Custom post model

Post is deliberately not final. Subclass it and point posts.model at your class:

namespace App\Models;

use RoundlyConsulting\Posts\Models\Post;

class Article extends Post
{
    // your relations, scopes, accessors and overrides
}
// config/posts.php
'model' => App\Models\Article::class,

The package resolves posts.model everywhere — in create(), publishDue() and the scheduled-publish command, the listeners, route binding, HasPosts, the category and tag posts() relations and the post factory — so your subclass is what gets created, queried and bound. In host code, reach it through the facade:

use RoundlyConsulting\Posts\Facades\Posts;

Posts::query();                    // Builder over the configured model (Article)
Posts::published();                // its published() scope
Posts::findBySlug('hello-world');  // ?Article
Posts::create($data);              // creates an Article

Absent or blank config resolves Post; any other value must be Post or a subclass of it, or the toolkit’s InvalidConfigurationException is thrown naming the key — a foreign class is never silently replaced. Post::findBySlug() always uses the packaged class — use Posts::findBySlug() or Posts::query() instead. Category and Tag are final.

Other extension points

  • Tables — rename any table under posts.tables.* before migrating.
  • Keys — key_type and primary_key_type before migrating.
  • SEO and JSON-LD — the seo.* and json-ld.* defaults, setSeo() per post, and the published posts-views.
  • Workflow hooks — listen to the four lifecycle events.
  • Media — bucket names, disk, widths, the og:image variant and inline behaviour under posts.media.*.
  • Moderation — posts.moderation.*, or listen to the reports events yourself.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.