From 5ce904c4b13867e5dd4d773b11766edc1a32f61a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 24 Jun 2020 17:53:14 +0100 Subject: [PATCH 1/2] Allow setting custom primary keys --- src/Generators/FactoryGenerator.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index ea431b8..87f32d2 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -26,18 +26,32 @@ class FactoryGenerator extends EntityGenerator { /** - * Generate, and return the attribute. + * The primary key methods. * * @var string[] */ - private static $methods = ['getKey', 'pk']; + private static $methods; /** - * The factory properties. + * The primary key properties. * * @var string[] */ - private static $properties = ['id', '_id', 'Id']; + private static $properties; + + /** + * Create a new factory generator instance. + * + * @param string[]|null $methods The primary key methods. + * @param string[]|null $properties The primary key properties. + * + * @return void + */ + public function __construct(array $methods = null, array $properties = null) + { + $this->methods = $methods ?: ['getKey', 'pk']; + $this->properties = $properties ?: ['id', '_id', 'Id']; + } /** * Generate, and return the attribute. From 2ff67d5bde27693a3401bb40279dad12769b4683 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 24 Jun 2020 16:53:23 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/Generators/FactoryGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 87f32d2..0214ef2 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -42,7 +42,7 @@ class FactoryGenerator extends EntityGenerator /** * Create a new factory generator instance. * - * @param string[]|null $methods The primary key methods. + * @param string[]|null $methods The primary key methods. * @param string[]|null $properties The primary key properties. * * @return void