first upload all files

This commit is contained in:
NW
2023-06-11 13:14:03 +01:00
parent f14dbc52b5
commit c08b36d1b6
1705 changed files with 106852 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
<?php
namespace Modules\Attribute\Http\Requests;
use Illuminate\Validation\Rule;
use Modules\Core\Http\Requests\Request;
use Modules\Attribute\Entities\Attribute;
class SaveAttributeRequest extends Request
{
/**
* Available attributes.
*
* @var string
*/
protected $availableAttributes = 'attribute::attributes.attributes';
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'attribute_set_id' => ['required', Rule::exists('attribute_sets', 'id')],
'name' => 'required',
'slug' => $this->getSlugRules(),
'is_filterable' => 'required|boolean',
];
}
private function getSlugRules()
{
$rules = $this->route()->getName() === 'admin.attributes.update'
? ['required']
: ['sometimes'];
$slug = Attribute::where('id', $this->id)->value('slug');
$rules[] = Rule::unique('attributes', 'slug')->ignore($slug, 'slug');
return $rules;
}
/**
* Get data to be validated from the request.
*
* @return array
*/
public function validationData()
{
return request()->merge([
'values' => $this->filter($this->values ?? []),
])->all();
}
/**
* Filter attribute values.
*
* @param array $values
* @return array
*/
private function filter($values = [])
{
return array_filter($values, function ($value) {
return ! is_null($value['value']);
});
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Modules\Attribute\Http\Requests;
use Modules\Core\Http\Requests\Request;
class SaveAttributeSetRequest extends Request
{
/**
* Available attributes.
*
* @var string
*/
protected $availableAttributes = 'attribute::attributes.attribute_sets';
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
];
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Modules\Attribute\Http\Requests;
use Illuminate\Validation\Rule;
use Modules\Core\Http\Requests\Request;
class SaveProductAttributesRequest extends Request
{
/**
* Available attributes.
*
* @var string
*/
protected $availableAttributes = 'attribute::attributes.product_attributes';
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'attributes.*.attribute_id' => ['required_with:attributes.*.values', Rule::exists('attributes', 'id')],
'attributes.*.values' => ['required_with:attributes.*.attribute_id', Rule::exists('attribute_values', 'id')],
];
}
/**
* Get data to be validated from the request.
*
* @return array
*/
public function validationData()
{
if (empty($this->except('attributes'))) {
return request()->all();
}
return request()->merge([
'attributes' => $this->filter($this->get('attributes', [])),
])->all();
}
/**
* Filter product attributes.
*
* @param array $attributes
* @return array
*/
private function filter($attributes = [])
{
return array_filter($attributes, function ($attribute) {
return ! is_null($attribute['attribute_id']);
});
}
}