# How to create factories for models with polymorphic relationships in Laravel

DevFeed: [How to create factories for models with polymorphic relationships in Laravel](<https://devfeed.tech/articles/how-to-create-factories-for-models-with-polymorphic-relationships-in-laravel-37162.md>)

Original publisher: [Read original article](<https://arkadiuszchmura.com/posts/how-to-create-factories-for-models-with-polymorphic-relationships-in-laravel/>)

Published: 2023-03-29T00:00:00Z

Content type: tutorial

Language: en

Sources: [Arkadiusz Chmura](<https://devfeed.tech/sources/arkadiusz-chmura.md>)

Topics: [Laravel](<https://devfeed.tech/topics/laravel.md>), [Eloquent ORM](<https://devfeed.tech/topics/eloquent.md>), [Code](<https://devfeed.tech/topics/code.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [eloquent](<https://devfeed.tech/tags/eloquent.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [laravel](<https://devfeed.tech/tags/laravel.md>), [relationships](<https://devfeed.tech/tags/relationships.md>), [users](<https://devfeed.tech/tags/users.md>)

## AI overview

A Laravel tutorial explaining how to build model factories for polymorphic relationships, including custom morph aliases and factory states for associating different related models.

## Source excerpt

Factories for these models are a bit trickier to implement than the standard ones.