Skip to content

Commit

Permalink
use callback only in state
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 24, 2020
1 parent b63eddb commit 94a85f7
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions database-testing.md
Original file line number Diff line number Diff line change
@@ -128,21 +128,7 @@ Via the `faker` property, factories have access to the [Faker](https://github.co
<a name="factory-states"></a>
### Factory States

State manipulation methods allow you to define discrete modifications that can be applied to your model factories in any combination. For example, your `User` model might have a `suspended` state that modifies one of its default attribute values. You may define your state transformations using the base factory's `state` method. You may name your state method anything you like. After all, it's just a typical PHP method:

/**
* Indicate that the user is suspended.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function suspended()
{
return $this->state([
'account_status' => 'suspended',
]);
}

If your state transformation requires access to the other attributes defined by the factory, you may pass a callback to the `state` method. The callback will receive the array of raw attributes defined for the factory:
State manipulation methods allow you to define discrete modifications that can be applied to your model factories in any combination. For example, your `User` model might have a `suspended` state that modifies one of its default attribute values. You may define your state transformations using the base factory's `state` method. You may name your state method anything you like. After all, it's just a typical PHP method. The provided state manipulation callback will receive the array of raw attributes defined for the factory and should return an array of attributes to modify:

/**
* Indicate that the user is suspended.

0 comments on commit 94a85f7

Please sign in to comment.