2019-12-13 13:59:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
namespace Webkul\Attribute\Database\Factories;
|
2019-12-13 13:59:45 +00:00
|
|
|
|
|
|
|
|
use Webkul\Attribute\Models\Attribute;
|
2021-10-04 08:30:32 +00:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
|
|
|
|
|
|
class AttributeFactory extends Factory
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $model = Attribute::class;
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
/**
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $states = [
|
|
|
|
|
'validation_numeric',
|
|
|
|
|
'validation_email',
|
|
|
|
|
'validation_decimal',
|
|
|
|
|
'validation_url',
|
|
|
|
|
'required',
|
|
|
|
|
'unique',
|
|
|
|
|
'filterable',
|
|
|
|
|
'configurable',
|
|
|
|
|
];
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
/**
|
|
|
|
|
* Define the model's default state.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function definition(): array
|
|
|
|
|
{
|
|
|
|
|
$types = [
|
|
|
|
|
'text',
|
|
|
|
|
'textarea',
|
|
|
|
|
'price',
|
|
|
|
|
'boolean',
|
|
|
|
|
'select',
|
|
|
|
|
'multiselect',
|
|
|
|
|
'datetime',
|
|
|
|
|
'date',
|
|
|
|
|
'image',
|
|
|
|
|
'file',
|
|
|
|
|
'checkbox',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'admin_name' => $this->faker->word,
|
|
|
|
|
'code' => $this->faker->word,
|
|
|
|
|
'type' => array_rand($types),
|
|
|
|
|
'validation' => '',
|
|
|
|
|
'position' => $this->faker->randomDigit,
|
|
|
|
|
'is_required' => false,
|
|
|
|
|
'is_unique' => false,
|
|
|
|
|
'value_per_locale' => false,
|
|
|
|
|
'value_per_channel' => false,
|
|
|
|
|
'is_filterable' => false,
|
|
|
|
|
'is_configurable' => false,
|
|
|
|
|
'is_user_defined' => true,
|
|
|
|
|
'is_visible_on_front' => true,
|
|
|
|
|
'swatch_type' => null,
|
|
|
|
|
'use_in_flat' => true,
|
2019-12-13 13:59:45 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
public function validation_numeric(): AttributeFactory
|
|
|
|
|
{
|
|
|
|
|
return $this->state(function (array $attributes) {
|
|
|
|
|
return [
|
|
|
|
|
'validation' => 'numeric',
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
public function validation_email(): AttributeFactory
|
|
|
|
|
{
|
|
|
|
|
return $this->state(function (array $attributes) {
|
|
|
|
|
return [
|
|
|
|
|
'validation' => 'email',
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
public function validation_decimal(): AttributeFactory
|
|
|
|
|
{
|
|
|
|
|
return $this->state(function (array $attributes) {
|
|
|
|
|
return [
|
|
|
|
|
'validation' => 'decimal',
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
public function validation_url(): AttributeFactory
|
|
|
|
|
{
|
|
|
|
|
return $this->state(function (array $attributes) {
|
|
|
|
|
return [
|
|
|
|
|
'validation' => 'url',
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
public function required(): AttributeFactory
|
|
|
|
|
{
|
|
|
|
|
return $this->state(function (array $attributes) {
|
|
|
|
|
return [
|
|
|
|
|
'is_required' => true,
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
public function unique(): AttributeFactory
|
|
|
|
|
{
|
|
|
|
|
return $this->state(function (array $attributes) {
|
|
|
|
|
return [
|
|
|
|
|
'is_unique' => true,
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
public function filterable(): AttributeFactory
|
|
|
|
|
{
|
|
|
|
|
return $this->state(function (array $attributes) {
|
|
|
|
|
return [
|
|
|
|
|
'is_filterable' => true,
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-13 13:59:45 +00:00
|
|
|
|
2021-10-04 08:30:32 +00:00
|
|
|
public function configurable(): AttributeFactory
|
|
|
|
|
{
|
|
|
|
|
return $this->state(function (array $attributes) {
|
|
|
|
|
return [
|
|
|
|
|
'is_configurable' => true,
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|