PHPackages                             styde/factory - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. styde/factory

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

styde/factory
=============

Generate and build model factories for Laravel using classes and methods instead of closures

168PHP

Since Jan 17Pushed 8y ago2 watchersCompare

[ Source](https://github.com/StydeNet/factory)[ Packagist](https://packagist.org/packages/styde/factory)[ RSS](/packages/styde-factory/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Stydnet Factory Package
=======================

[](#stydnet-factory-package)

This packages allows you to build model factories for Laravel 5.4 using classes and methods instead of closures.

How to install
--------------

[](#how-to-install)

Install by running `composer require styde/factory:"dev-master" --dev`or adding `"styde/factory": "dev-master"` to the dev dependencies (`require-dev`) in the project's composer.json file and then running composer update.

Then create a "factory-classes" directory inside "database" and add the following to the "autoload-dev" section in your composer.json file:

```
      "autoload-dev": {
          "classmap": [
              "database/factory-classes",

```

And then execute `composer dump-autoload` in the console.

**Note**: you can put the factory classes anywhere you want and of course you can also use PSR-4 if you want to.

**Warning**: Laravel loads the database/factories/ multiple times during the test cycle. This will cause a conflict since you cannot override classes. So please don't put the factory classes in the database/factories directory, unless you are completely sure you are not using the `factory` helper.

Creating Factory Classes:
-------------------------

[](#creating-factory-classes)

The factory classes have the following structure:

```
