diff --git a/src/Illuminate/Database/Eloquent/FactoryBuilder.php b/src/Illuminate/Database/Eloquent/FactoryBuilder.php index 0fc522c1a109..7f4eccaa9da8 100644 --- a/src/Illuminate/Database/Eloquent/FactoryBuilder.php +++ b/src/Illuminate/Database/Eloquent/FactoryBuilder.php @@ -313,7 +313,7 @@ protected function stateAttributes($state, array $attributes) protected function expandAttributes(array $attributes) { foreach ($attributes as &$attribute) { - if (is_callable($attribute) && ! is_string($attribute)) { + if (is_callable($attribute) && ! is_string($attribute) && ! is_array($attribute)) { $attribute = $attribute($attributes); } diff --git a/tests/Integration/Database/EloquentFactoryBuilderTest.php b/tests/Integration/Database/EloquentFactoryBuilderTest.php index 3553b02d9436..395b652d5e76 100644 --- a/tests/Integration/Database/EloquentFactoryBuilderTest.php +++ b/tests/Integration/Database/EloquentFactoryBuilderTest.php @@ -42,6 +42,7 @@ protected function getEnvironmentSetUp($app) return [ 'name' => $faker->name, 'status' => 'active', + 'tags' => ['Storage', 'Data'], 'user_id' => function () { return factory(FactoryBuildableUser::class)->create()->id; }, @@ -80,6 +81,7 @@ public function setUp() Schema::create('servers', function ($table) { $table->increments('id'); $table->string('name'); + $table->string('tags'); $table->integer('user_id'); $table->string('status'); }); @@ -134,6 +136,7 @@ public function creating_models_with_callable_states() $callableServer = factory(FactoryBuildableServer::class)->states('callable')->create(); $this->assertEquals('active', $server->status); + $this->assertEquals(['Storage', 'Data'], $server->tags); $this->assertEquals('callable', $callableServer->status); } @@ -208,6 +211,7 @@ class FactoryBuildableServer extends Model public $table = 'servers'; public $timestamps = false; protected $guarded = ['id']; + public $casts = ['tags' => 'array']; public function user() {