### Installation Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md Instructions on how to install Factory Muffin and its Faker support using Composer. ```APIDOC ## Installation Requires [PHP](https://php.net) 5.4+ and [Composer](https://getcomposer.org). Add the following to your `composer.json`'s `require-dev` section: ```json { "require-dev": { "league/factory-muffin": "^3.3" } } ``` For Faker support, also add `league/factory-muffin-faker`: ```json { "require-dev": { "league/factory-muffin": "^3.3", "league/factory-muffin-faker": "^2.3" } } ``` ``` -------------------------------- ### Install Factory Muffin 3.0 via Composer Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Add the required dependency to your composer.json file to install version 3.0 of Factory Muffin. ```json { "require-dev": { "league/factory-muffin": "3.0.*" } } ``` -------------------------------- ### Loading Factories from Directory Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Shows how to load all factory definitions from a specified directory using the `loadFactories` function. This function is designed to be used within test setup methods like PHPUnit's `setupBeforeClass`. It will throw a `DirectoryNotFoundException` if the provided directory does not exist. ```PHP League\FactoryMuffin\Facade::loadFactories(__DIR__ . '/factories'); ``` -------------------------------- ### Defining Factories with `define` Function Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Illustrates the recommended way to define factories using the `define` function, replacing the older static factory property method. This approach is particularly useful within PHPUnit's `setupBeforeClass` for test setup. ```PHP League\FactoryMuffin\Facade::define('Fully\Qualified\ModelName', array('foo' => 'bar')); ``` -------------------------------- ### Install Factory Muffin - JSON Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Specifies the dependency for Factory Muffin version 2.1.* in the composer.json file for development dependencies. ```JSON { "require-dev": { "league/factory-muffin": "2.1.*" } } ``` -------------------------------- ### Define Model Factories with Factory Muffin Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md Shows how to define model factories using Factory Muffin, including setting attributes with Faker data, defining relationships, and using callbacks for custom logic. This is typically done in a test setup file. ```php # tests/factories/all.php use League\FactoryMuffin\Faker\Facade as Faker; $fm->define('Message')->setDefinitions([ 'user_id' => 'factory|User', 'subject' => Faker::sentence(), 'message' => Faker::text(), 'phone_number' => Faker::randomNumber(8), 'created' => Faker::date('Ymd h:s'), 'slug' => 'Message::makeSlug', ])->setCallback(function ($object, $saved) { // we're taking advantage of the callback functionality here $object->message .= '!'; }); $fm->define('User')->setDefinitions([ 'username' => Faker::firstNameMale(), 'email' => Faker::email(), 'avatar' => Faker::imageUrl(400, 600), 'greeting' => 'RandomGreeting::get', 'four' => function() { return 2 + 2; }, ]); ``` -------------------------------- ### Installing Factory Muffin via Composer Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Provides the Composer `require-dev` statements for installing specific versions of the Factory Muffin library. This includes instructions for versions 2.0.*, 1.6.*, and 1.5.*. ```json { "require-dev": { "league/factory-muffin": "2.0.*" } } ``` ```json { "require-dev": { "league/factory-muffin": "1.6.*" } } ``` ```json { "require-dev": { "league/factory-muffin": "1.5.*" } } ``` -------------------------------- ### PHP Factory Muffin Exception Handling Examples Source: https://context7.com/thephpleague/factory-muffin/llms.txt Demonstrates how to catch and handle various exceptions thrown by Factory Muffin, including DefinitionNotFoundException, DefinitionAlreadyDefinedException, ModelNotFoundException, SaveMethodNotFoundException, SaveFailedException, and DirectoryNotFoundException. These examples show how to access error messages and specific details from the exceptions. ```php create('NonExistentModel'); } catch (DefinitionNotFoundException $e) { echo $e->getDefinitionName(); // "NonExistentModel" echo $e->getMessage(); // "The model definition 'NonExistentModel' is undefined." } // DefinitionAlreadyDefinedException - duplicate definition $fm->define('App\Models\User'); try { $fm->define('App\Models\User'); // Already defined! } catch (DefinitionAlreadyDefinedException $e) { echo $e->getMessage(); } // ModelNotFoundException - class doesn't exist $fm->define('NonExistent\Class'); try { $fm->create('NonExistent\Class'); } catch (ModelNotFoundException $e) { echo $e->getMessage(); } // SaveMethodNotFoundException - save() method missing $fm->define('ModelWithoutSave'); try { $fm->create('ModelWithoutSave'); } catch (SaveMethodNotFoundException $e) { echo $e->getModelClass(); // "ModelWithoutSave" echo $e->getMethodName(); // "save" } // SaveFailedException - save() returned false // Handles validation errors if $model->validationErrors is set try { $fm->create('ModelThatFailsValidation'); } catch (SaveFailedException $e) { echo $e->getModelClass(); echo $e->getValidationErrors(); // e.g., "Email is required" } // DirectoryNotFoundException - factory directory doesn't exist try { $fm->loadFactories('/nonexistent/path'); } catch (DirectoryNotFoundException $e) { echo $e->getMessage(); } ``` -------------------------------- ### Initialize and Use Factory Muffin in PHPUnit Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md This snippet shows the standard lifecycle for Factory Muffin in a PHPUnit test class, including setup, factory loading, model creation, and cleanup. ```php use League\\FactoryMuffin\\Faker\\Facade as Faker; class TestUserModel extends PHPUnit_Framework_TestCase { protected static $fm; public static function setupBeforeClass() { static::$fm = new FactoryMuffin(); static::$fm->loadFactories(__DIR__.'/factories'); Faker::setLocale('en_EN'); } public function testSampleFactory() { $message = static::$fm->create('Message'); $this->assertInstanceOf('Message', $message); $this->assertInstanceOf('User', $message->user); } public static function tearDownAfterClass() { static::$fm->deleteSaved(); } } ``` -------------------------------- ### Install Factory Muffin with Faker Support Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md Include both Factory Muffin and the Faker extension in your composer.json. This enables advanced data generation capabilities for your test objects. ```json { "require-dev": { "league/factory-muffin": "^3.3", "league/factory-muffin-faker": "^2.3" } } ``` -------------------------------- ### Generator Syntax Changes (Faker Alternatives) Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Provides examples of how to use Faker generators as replacements for removed built-in generators. This includes using `randomNumber` for integers, `sentence` or `word` for strings, and specific Faker methods for names. ```PHP // Instead of integer|8 'id' => 'randomNumber|8', // Instead of string 'title' => 'sentence', // Instead of name 'author' => 'firstNameMale' ``` -------------------------------- ### Install Factory Muffin via Composer Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md Add Factory Muffin to your project's composer.json file to manage dependencies for testing. This configuration ensures the library is available in your development environment. ```json { "require-dev": { "league/factory-muffin": "^3.3" } } ``` -------------------------------- ### Faker Usage and Custom Attributes in Factory Muffin Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Details the integration of the Faker library starting from version 1.6.x, replacing the `Wordlist` class. It explains how definitions now fall back to Faker and introduces the use of closures for generating custom attributes within the `Kind` namespace. ```php use Zizaco\FactoryMuff\Kind\Faker; // Example using Faker for attributes FactoryMuff::define('App\Post', [ 'title' => Faker::title(), 'body' => Faker::text() ]); // Example using a closure for custom attributes FactoryMuff::define('App\User', [ 'registered_at' => function() { return date('Y-m-d H:i:s'); } ]); ``` -------------------------------- ### Initialize Factory Muffin Instance Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Demonstrates the transition from static Facade usage in 2.x to instance-based initialization in 3.x within a test case. ```php // 2.x approach static function setupBeforeClass() { Facade::loadFactories(__DIR__ . '/factories'); } // 3.x approach function setUp() { parent::setUp(); $this->fm = new FactoryMuffin(); $this->fm->loadFactories(__DIR__ . '/factories'); } ``` -------------------------------- ### Create Models via Instance Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Shows how to replace static Facade calls with instance method calls for creating models in 3.x. ```php // 2.x Facade::create('ShinyObject'); // 3.x $this->fm->create('ShinyObject'); ``` -------------------------------- ### Creating and Seeding Models with Factory Muffin Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Demonstrates how to create single or multiple model instances using the `create` and `seed` functions. It also shows how to set custom save methods and use the `instance` function for non-persistent generation. Exceptions like `NoDefinedFactoryException` and `SaveFailedException` are noted. ```php use League\FactoryMuffin\FactoryMuffin; // Create a single model $user = FactoryMuffin::create('App\User'); // Create multiple models $users = FactoryMuffin::seed(10, 'App\User'); // Set a custom save method FactoryMuffin::setSaveMethod(function($model) { // custom save logic return $model->save(); }); // Use instance for non-persistent generation $userInstance = FactoryMuffin::instance('App\User'); ``` -------------------------------- ### Defining Model Factories with Factory Muffin Source: https://context7.com/thephpleague/factory-muffin/llms.txt Demonstrates how to initialize Factory Muffin, define a model factory with various Faker-generated attributes, and create instances with or without database persistence. ```php define('App\Models\User')->setDefinitions([ 'username' => Faker::userName(), 'email' => Faker::email(), 'password' => Faker::password(), 'first_name' => Faker::firstNameMale(), 'last_name' => Faker::lastName(), 'bio' => Faker::text(200), 'avatar' => Faker::imageUrl(400, 400), 'is_active' => Faker::boolean(), 'created_at' => Faker::date('Y-m-d H:i:s'), ]); $user = $fm->instance('App\Models\User'); echo $user->email; $savedUser = $fm->create('App\Models\User'); echo $savedUser->id; ``` -------------------------------- ### Create and Seed Models with Factory Muffin Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md Demonstrates how to create single model instances and seed multiple instances with associated models using Factory Muffin. It shows how to specify the number of models to generate and set relationships. ```php $user = $fm->create('User'); $profiles = $fm->seed(5, 'Location', ['user_id' => $user->id]); $emails = $fm->seed(100, 'Email', ['user_id' => $user->id]); foreach ($emails as $email) { $tokens = $fm->seed(50, 'Token', ['email_id' => $email->id]); } ``` -------------------------------- ### POST /create Source: https://context7.com/thephpleague/factory-muffin/llms.txt Creates and persists a single model instance based on a defined factory. ```APIDOC ## POST /create ### Description Generates a new instance of the specified model, automatically resolving relationships and persisting the data. ### Method POST ### Endpoint /create ### Parameters #### Request Body - **modelName** (string) - Required - The model identifier defined previously. ### Response #### Success Response (200) - **instance** (object) - The created model instance with populated attributes. ``` -------------------------------- ### Using Static Methods as Generators Source: https://context7.com/thephpleague/factory-muffin/llms.txt Demonstrates how to reference static class methods as attribute generators within a factory definition. ```php define('App\Models\Subscription')->setDefinitions([ 'code' => 'DateHelper::generateCode', 'expires_at' => 'DateHelper::futureDate', 'plan' => 'premium', ]); $subscription = $fm->instance('App\Models\Subscription'); echo $subscription->code; echo $subscription->expires_at; ``` -------------------------------- ### Load Factory Definitions from Files Source: https://context7.com/thephpleague/factory-muffin/llms.txt Use loadFactories to organize model definitions into separate PHP files within a directory, keeping test suites clean and modular. ```php public static function setUpBeforeClass(): void { static::$fm = new FactoryMuffin(); static::$fm->loadFactories(__DIR__ . '/factories'); } ``` -------------------------------- ### Using Generators with Multiple Arguments Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Demonstrates the updated syntax for using generators, specifically how to pass multiple arguments by separating them with a semicolon. This applies to generators like `Call`, `Closure`, `Factory`, and `Generic`. ```PHP League\FactoryMuffin\Facade::define('User', [ 'name' => 'unique:name;John Doe', 'email' => 'unique:email;john@example.com' ]); ``` -------------------------------- ### Accessing Facade in Factory Muffin Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Demonstrates how to access the Factory Muffin facade after its namespace has been changed from Zizaco\FactoryMuff to League\FactoryMuffin. This change affects how you instantiate and use the facade's methods. ```PHP echo League\FactoryMuffin\Facade::fooBar(); ``` -------------------------------- ### Configure Custom Save and Delete Methods with ModelStore Source: https://context7.com/thephpleague/factory-muffin/llms.txt Demonstrates how to use `ModelStore` to specify custom method names for saving and deleting models. This is useful when your application's models use persistence methods other than the default 'save' and 'delete'. ```php define('App\Models\Entity')->setDefinitions([ 'name' => Faker::word(), ]); // Now Factory Muffin will call: // - $model->persist() instead of $model->save() // - $model->remove() instead of $model->delete() $entity = $fm->create('App\Models\Entity'); // Calls $entity->persist() $fm->deleteSaved(); // Calls $entity->remove() ``` -------------------------------- ### Generate Related Models with Factory Syntax Source: https://context7.com/thephpleague/factory-muffin/llms.txt Demonstrates the use of the 'factory|ModelName' syntax to automatically create and persist related models, assigning their IDs to foreign key attributes. ```php define('App\Models\Author')->setDefinitions([ 'name' => Faker::name(), 'email' => Faker::email(), ]); $fm->define('App\Models\Category')->setDefinitions([ 'name' => Faker::word(), 'slug' => Faker::slug(), ]); $fm->define('App\Models\Book')->setDefinitions([ 'title' => Faker::sentence(4), 'isbn' => Faker::isbn13(), 'author_id' => 'factory|App\Models\Author', 'category_id' => 'factory|App\Models\Category', 'price' => Faker::randomFloat(2, 9.99, 99.99), ]); $book = $fm->create('App\Models\Book'); echo $book->author_id; echo $book->category_id; ``` -------------------------------- ### Defining Factory Models with Factory Muffin Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Illustrates the modern approach to defining factory models by using the `define` method, which is the recommended practice over the deprecated static `$factory` property. This method allows specifying model names and their corresponding attribute arrays. ```php use Zizaco\FactoryMuff\Facade\FactoryMuff; // Define a factory for a model FactoryMuff::define('Fully\Qualified\ModelName', [ 'foo' => 'bar', 'baz' => 'qux' ]); // Deprecated method (still supported but will be removed in 2.0) // class MyModel { // public static $factory = ['foo' => 'bar']; // } ``` -------------------------------- ### loadFactories() Source: https://context7.com/thephpleague/factory-muffin/llms.txt Loads multiple factory definitions from a directory of PHP files. ```APIDOC ## loadFactories(string $directory) ### Description Recursively loads all PHP files within a specified directory to register factory definitions. The $fm instance is automatically injected into the scope of these files. ### Method POST/Configuration ### Parameters - **directory** (string) - Required - The path to the directory containing factory definition files. ### Request Example $fm->loadFactories(__DIR__ . '/factories'); ``` -------------------------------- ### Model Definitions Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md How to define model factories using the `define` method and generate attributes. ```APIDOC ## Model Definitions Define model factories using the `define` function on a FactoryMuffin instance (e.g., `$fm`). ### Basic Definition Define attributes for a model: ```php $fm->define('Fully\Qualified\ModelName')->addDefinitions('foo', 'bar'); $fm->define('Fully\Qualified\ModelName')->setDefinitions('foo', 'bar'); // Define multiple attributes ``` ### Grouped Definitions Define models within groups using a prefix: ```php $fm->define('myGroup:Fully\Qualified\ModelName')->addDefinitions('bar', 'baz'); ``` **Note:** When using group prefixes, a non-prefixed definition for the same model must also exist. ### Loading Factories Load factory definitions from a directory, recursively: ```php $fm->loadFactories(__DIR__ . '/factories'); ``` This function ignores hidden folders and throws a `DirectoryNotFoundException` if the directory does not exist. ``` -------------------------------- ### POST /define Source: https://context7.com/thephpleague/factory-muffin/llms.txt Defines a new model factory with specific attributes and relationships. ```APIDOC ## POST /define ### Description Defines a model schema for FactoryMuffin. Supports standard attributes and relationship generators like 'factory|' (for foreign keys) and 'entity|' (for full objects). ### Method POST ### Endpoint /define ### Parameters #### Request Body - **modelName** (string) - Required - The fully qualified class name of the model. - **definitions** (array) - Required - Key-value pairs of attributes, using 'factory|Model' or 'entity|Model' for relations. ### Request Example { "modelName": "App\\Models\\Book", "definitions": { "title": "Faker::sentence", "author_id": "factory|App\\Models\\Author" } } ``` -------------------------------- ### Define Model Variations with Groups Source: https://context7.com/thephpleague/factory-muffin/llms.txt Demonstrates how to create multiple definition groups for a single model, allowing for inheritance and attribute overrides. ```php define('App\Models\User')->setDefinitions([ 'name' => Faker::name(), 'email' => Faker::email(), 'role' => 'user', 'is_admin' => false, 'verified' => false, ]); $fm->define('admin:App\Models\User')->setDefinitions([ 'role' => 'administrator', 'is_admin' => true, 'verified' => true, ]); $fm->define('unverified:App\Models\User')->setDefinitions([ 'verified' => false, 'email' => Faker::freeEmail(), ]); $regularUser = $fm->create('App\Models\User'); $adminUser = $fm->create('admin:App\Models\User'); ``` -------------------------------- ### setMaker() Source: https://context7.com/thephpleague/factory-muffin/llms.txt Customizes the instantiation process for models requiring dependency injection or static factory methods. ```APIDOC ## setMaker(callable $maker) ### Description Defines a custom closure to handle the instantiation of a model, allowing for constructor dependency injection or the use of static factory methods. ### Method POST/Configuration ### Parameters - **maker** (callable) - Required - A function receiving the class name and returning the instantiated object. ### Request Example $fm->define('App\Models\Invoice')->setMaker(function ($class) { return new $class(new TaxCalculator(), new InvoiceFormatter()); }); ``` -------------------------------- ### Adding Single Attribute Definitions Source: https://context7.com/thephpleague/factory-muffin/llms.txt Shows how to use the addDefinition method to incrementally build factory definitions for a model. ```php define('App\Models\Post') ->addDefinition('title', Faker::sentence(5)) ->addDefinition('body', Faker::paragraphs(3, true)) ->addDefinition('published', false) ->addDefinition('views', Faker::numberBetween(0, 10000)); $post = $fm->instance('App\Models\Post'); echo $post->title; echo $post->views; ``` -------------------------------- ### Using Closures for Dynamic Attributes Source: https://context7.com/thephpleague/factory-muffin/llms.txt Explains how to use closures in factory definitions to generate attributes dynamically based on the model instance state or other attributes. ```php define('App\Models\Article')->setDefinitions([ 'title' => Faker::sentence(5), 'slug' => function ($object, $saved) { $slug = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $object->title); $slug = strtolower(trim($slug, '-')); return preg_replace("/[\/_|+ -]+/", '-', $slug); }, 'published_at' => function ($object, $saved) { return $saved ? date('Y-m-d H:i:s') : null; }, 'full_url' => function ($object, $saved) { return 'https://example.com/articles/' . $object->slug; }, ]); $article = $fm->instance('App\Models\Article'); echo $article->title; echo $article->slug; echo $article->full_url; ``` -------------------------------- ### Model Creation and Seeding Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Methods for creating model instances with database persistence or as simple objects, and seeding multiple models. ```APIDOC ## POST /factory/create ### Description Creates a model instance and saves it to the database using the defined factory. It also saves any associated generated models. ### Method POST ### Endpoint /factory/create ### Parameters #### Request Body - **modelClass** (string) - Required - The fully qualified class name of the model to create. ### Response #### Success Response (200) - **instance** (object) - The created and saved model instance. --- ## POST /factory/seed ### Description Generates and saves a specified number of model instances by repeatedly calling the create function. ### Method POST ### Endpoint /factory/seed ### Parameters #### Request Body - **count** (integer) - Required - Number of models to generate. - **modelClass** (string) - Required - The fully qualified class name of the model to seed. ``` -------------------------------- ### Generate Full Related Objects with Entity Syntax Source: https://context7.com/thephpleague/factory-muffin/llms.txt Shows how to use the 'entity|ModelName' syntax to retrieve the full related model instance instead of just the foreign key ID. ```php define('App\Models\Company')->setDefinitions([ 'name' => Faker::company(), 'address' => Faker::address(), ]); $fm->define('App\Models\Employee')->setDefinitions([ 'name' => Faker::name(), 'email' => Faker::companyEmail(), 'company' => 'entity|App\Models\Company', ]); $employee = $fm->create('App\Models\Employee'); echo $employee->company->name; echo $employee->company->address; ``` -------------------------------- ### Seed Multiple Model Instances Source: https://context7.com/thephpleague/factory-muffin/llms.txt Explains the use of the seed() method to generate multiple model instances, including support for attribute overrides and toggling persistence. ```php define('App\Models\User')->setDefinitions([ 'name' => Faker::name(), 'email' => Faker::email(), 'role' => 'user', ]); $fm->define('App\Models\Comment')->setDefinitions([ 'body' => Faker::paragraph(), 'user_id' => 'factory|App\Models\User', ]); $users = $fm->seed(10, 'App\Models\User'); $admins = $fm->seed(5, 'App\Models\User', ['role' => 'admin']); $unsavedUsers = $fm->seed(3, 'App\Models\User', [], false); $user = $fm->create('App\Models\User'); $comments = $fm->seed(20, 'App\Models\Comment', ['user_id' => $user->id]); ``` -------------------------------- ### Track Pending and Saved Models Source: https://context7.com/thephpleague/factory-muffin/llms.txt Explains how Factory Muffin tracks the state of models (pending vs. saved), enabling verification of their persistence status during testing. It also shows how to use callbacks to react to model states. ```php define('App\Models\User')->setDefinitions([ 'name' => Faker::name(), 'email' => Faker::email(), ]); // Instance only - not saved $instanceUser = $fm->instance('App\Models\User'); // Check status echo $fm->isPendingOrSaved($instanceUser); // false // Create and save $savedUser = $fm->create('App\Models\User'); // Check status echo $fm->isPendingOrSaved($savedUser); // true // Create multiple $fm->seed(5, 'App\Models\User'); // Access via reflection or internal store for testing // In callbacks and closures, use isPendingOrSaved to check state $fm->define('App\Models\Profile')->setDefinitions([ 'bio' => Faker::text(), ])->setCallback(function ($profile, $saved) use ($fm) { if ($saved) { echo "Profile will be persisted to database"; } else { echo "Profile is instance only"; } }); ``` -------------------------------- ### Define Model Creation Callback Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md Registers a callback to be executed during model creation or instantiation. The callback receives the model instance and a boolean indicating if the model is being persisted. ```php $fm->define('MyModel')->setCallback(function ($object, $saved) {}); ``` -------------------------------- ### Defining Model Callbacks Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md Configures a callback to be executed during model instantiation or creation. ```APIDOC ## setCallback ### Description Registers a callback function to be executed on model creation or instantiation. The callback receives the model instance and a boolean indicating if the model is being persisted. ### Method POST ### Endpoint $fm->define('ModelName')->setCallback(callable $callback) ### Parameters #### Request Body - **callback** (callable) - Required - A function with signature `function ($object, $saved)`. ### Request Example $fm->define('MyModel')->setCallback(function ($object, $saved) { // Logic here }); ``` -------------------------------- ### Closure Generator with Model Instance Source: https://github.com/thephpleague/factory-muffin/blob/master/UPGRADING.md Highlights a change in the Closure generator, which now passes the model instance as the first argument to the closure. This allows for more complex attribute generation logic that depends on the model itself. ```PHP League\FactoryMuffin\Facade::define('Order', [ 'total' => function($model) { return $model->quantity * $model->price; }, ]); ``` -------------------------------- ### Define Attributes with Static Methods Source: https://github.com/thephpleague/factory-muffin/blob/master/README.md Sets an attribute value by calling a static method on a model class. The method receives the model instance and the persistence status. ```php $fm->define('MyModel')->setDefinitions([ 'foo' => 'MyModel::exampleMethod', ]); ```