$this->faker->unique()->catchPhrase(), ]; } public function mobile() { return $this->state(function () { return [ 'name' => 'Mobile Devices', ]; }); } public function computer() { return $this->state(function () { return [ 'name' => 'Laptops and Desktops', ]; }); } public function hasEncryptedCustomField(CustomField $field = null) { return $this->afterCreating(function (CustomFieldset $fieldset) use ($field) { $field = $field ?? CustomField::factory()->testEncrypted()->create(); $fieldset->fields()->attach($field, ['order' => '1', 'required' => false]); }); } public function hasMultipleCustomFields(array $fields = null): self { return $this->afterCreating(function (CustomFieldset $fieldset) { if (empty($fields)) { //why are there two after creating and why does it break if i remove one return $this->afterCreating(function (CustomFieldset $fieldset) { $mac_address = CustomField::factory()->macAddress()->create(); $ram = CustomField::factory()->ram()->create(); $cpu = CustomField::factory()->cpu()->create(); $fieldset->fields()->attach($mac_address, ['order' => '1', 'required' => false]); $fieldset->fields()->attach($ram, ['order' => '2', 'required' => false]); $fieldset->fields()->attach($cpu, ['order' => '3', 'required' => false]); }); } else { foreach ($fields as $field) { $fieldset->fields()->attach($field, ['order' => '1', 'required' => false]); } } }); } }