---
title: "Authors — Posts for Laravel | Roundly"
description: "Polymorphic authorship — add HasPosts to any bigint-, UUID- or ULID-keyed model and attach it to a post."
url: https://roundly-consulting.com/open-source/docs/posts-for-laravel/authors
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Posts for Laravel](https://roundly-consulting.com/open-source/docs/posts-for-laravel.md)

# Authors

Authorship is polymorphic, so any model can write posts — a User, a Team, an Organization. Add the HasPosts trait to each author model:

```php
use Illuminate\Foundation\Auth\User as Authenticatable;
use RoundlyConsulting\Posts\Concerns\HasPosts;

final class User extends Authenticatable
{
    use HasPosts; // $user->posts (morphMany)
}
```

Pass the author to the Posts::draft() builder with by(), attach it through the morph relation, or give CreatePostData an authorType and authorId. The posts() relation goes through the configured post model, so post scopes chain straight off it:

```php
use RoundlyConsulting\Posts\Facades\Posts;

$post = Posts::draft()->title('en', 'Hello world')->by($user)->save();   // polymorphic author

// Or on the model:
$post->author()->associate($team);
$post->save();

$post->author;                        // the author model (User, Team, …)

$user->posts()->published()->latest('published_at')->get();
```

## Author options

- author.morph-name — the relation name and column prefix (author\_type / author\_id). Default author.
- author.nullable — whether a post may exist without an author. Default true.
- key\_type — the author\_id column type; it must match your author model’s key (bigint, uuid or ulid).
- json-ld.author-attribute — the author attribute used as the JSON-LD author name. Default name.

## 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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/posts-for-laravel.md)
