2018-09-29 22:17:36 -07:00
|
|
|
<?php
|
2021-06-10 13:19:27 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
namespace Database\Factories;
|
2021-06-10 13:19:27 -07:00
|
|
|
|
2023-03-20 11:39:27 -07:00
|
|
|
use App\Models\CustomFieldset;
|
2024-04-15 10:46:11 -07:00
|
|
|
use App\Models\CustomField;
|
2021-06-10 13:17:44 -07:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
2018-09-29 22:17:36 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
class CustomFieldsetFactory extends Factory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-03-20 11:39:27 -07:00
|
|
|
protected $model = CustomFieldset::class;
|
2018-09-29 22:17:36 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function definition()
|
|
|
|
{
|
|
|
|
return [
|
2023-09-19 17:02:18 -07:00
|
|
|
'name' => $this->faker->unique()->catchPhrase(),
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
}
|
2018-09-29 22:17:36 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
public function mobile()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'Mobile Devices',
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function computer()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
return [
|
|
|
|
'name' => 'Laptops and Desktops',
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2024-04-15 10:46:11 -07:00
|
|
|
|
2024-04-16 16:58:28 -07:00
|
|
|
public function hasEncryptedCustomField(CustomField $field = null)
|
2024-04-15 10:46:11 -07:00
|
|
|
{
|
2024-04-16 16:58:28 -07:00
|
|
|
return $this->afterCreating(function (CustomFieldset $fieldset) use ($field) {
|
|
|
|
$field = $field ?? CustomField::factory()->testEncrypted()->create();
|
|
|
|
|
|
|
|
$fieldset->fields()->attach($field, ['order' => '1', 'required' => false]);
|
2024-04-15 10:46:11 -07:00
|
|
|
});
|
|
|
|
}
|
2024-05-01 14:12:56 -07:00
|
|
|
|
|
|
|
public function hasMultipleCustomFields(array $fields = null): self
|
|
|
|
{
|
2024-05-07 12:08:47 -07:00
|
|
|
return $this->afterCreating(function (CustomFieldset $fieldset) use ($fields) {
|
2024-05-01 14:12:56 -07:00
|
|
|
if (empty($fields)) {
|
|
|
|
$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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-06-10 13:17:44 -07:00
|
|
|
}
|