-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from dbushy727/support-closures-for-model-data
Support closures for model data
- Loading branch information
Showing
4 changed files
with
86 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace ExampleAppTests\Factories; | ||
|
||
use Christophrumpel\LaravelFactoriesReloaded\BaseFactory; | ||
use ExampleApp\Models\Ingredient; | ||
use Faker\Generator; | ||
|
||
class IngredientFactoryUsingClosure extends BaseFactory | ||
{ | ||
protected string $modelClass = Ingredient::class; | ||
|
||
public function create(array $extra = []): Ingredient | ||
{ | ||
return parent::build($extra); | ||
} | ||
|
||
public function make(array $extra = []): Ingredient | ||
{ | ||
return parent::build($extra, 'make'); | ||
} | ||
|
||
public function getDefaults(Generator $faker): array | ||
{ | ||
return [ | ||
'name' => 'Pasta', | ||
'description' => function (array $ingredient) { | ||
return "Super delicious {$ingredient['name']}"; | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters