44
55use Exception ;
66use Faker \Provider \Lorem ;
7+ use Givebutter \LaravelCustomFields \Enums \CustomFieldType ;
78use Givebutter \LaravelCustomFields \Models \CustomField ;
89use Illuminate \Database \Eloquent \Factories \Factory ;
910
@@ -23,23 +24,15 @@ class CustomFieldFactory extends Factory
2324 */
2425 public function definition ()
2526 {
26- $ typesRequireAnswers = [
27- CustomField::TYPE_TEXT => false ,
28- CustomField::TYPE_RADIO => true ,
29- CustomField::TYPE_SELECT => true ,
30- CustomField::TYPE_NUMBER => false ,
31- CustomField::TYPE_CHECKBOX => false ,
32- CustomField::TYPE_TEXTAREA => false ,
33- ];
34-
35- $ type = array_keys ($ typesRequireAnswers )[rand (0 , count ($ typesRequireAnswers ) - 1 )]; // Pick a random type
27+ /** @var CustomFieldType $type */
28+ $ type = $ this ->faker ->randomElement (CustomFieldType::cases ());
3629
3730 return [
38- 'type ' => $ type ,
31+ 'type ' => $ type-> value ,
3932 'required ' => false ,
4033 'title ' => Lorem::sentence (3 ),
4134 'description ' => Lorem::sentence (3 ),
42- 'answers ' => $ typesRequireAnswers ? Lorem::words () : [],
35+ 'answers ' => $ type -> requiresAnswers () ? Lorem::words () : [],
4336 ];
4437 }
4538
@@ -48,7 +41,7 @@ public function definition()
4841 */
4942 public function withTypeCheckbox ()
5043 {
51- $ this ->model ->type = CustomField:: TYPE_CHECKBOX ;
44+ $ this ->model ->type = CustomFieldType:: CHECKBOX ;
5245
5346 return $ this ;
5447 }
@@ -58,7 +51,7 @@ public function withTypeCheckbox()
5851 */
5952 public function withTypeNumber ()
6053 {
61- $ this ->model ->type = CustomField:: TYPE_NUMBER ;
54+ $ this ->model ->type = CustomFieldType:: NUMBER ;
6255
6356 return $ this ;
6457 }
@@ -70,7 +63,7 @@ public function withTypeNumber()
7063 */
7164 public function withTypeRadio ($ answerCount = 3 )
7265 {
73- $ this ->model ->type = CustomField:: TYPE_RADIO ;
66+ $ this ->model ->type = CustomFieldType:: RADIO ;
7467
7568 return $ this ->withAnswers ($ answerCount );
7669 }
@@ -82,7 +75,7 @@ public function withTypeRadio($answerCount = 3)
8275 */
8376 public function withTypeSelect ($ optionCount = 3 )
8477 {
85- $ this ->model ->type = CustomField:: TYPE_SELECT ;
78+ $ this ->model ->type = CustomFieldType:: SELECT ;
8679
8780 return $ this ->withAnswers ($ optionCount );
8881 }
@@ -92,7 +85,7 @@ public function withTypeSelect($optionCount = 3)
9285 */
9386 public function withTypeText ()
9487 {
95- $ this ->model ->type = CustomField:: TYPE_TEXT ;
88+ $ this ->model ->type = CustomFieldType:: TEXT ;
9689
9790 return $ this ;
9891 }
@@ -102,7 +95,7 @@ public function withTypeText()
10295 */
10396 public function withTypeTextArea ()
10497 {
105- $ this ->model ->type = CustomField:: TYPE_TEXTAREA ;
98+ $ this ->model ->type = CustomFieldType:: TEXTAREA ;
10699
107100 return $ this ;
108101 }
0 commit comments