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,47 @@
<?php
namespace Modules\Attribute\Http\Controllers\Admin;
use Modules\Admin\Traits\HasCrudActions;
use Modules\Attribute\Entities\Attribute;
use Modules\Attribute\Http\Requests\SaveAttributeRequest;
class AttributeController
{
use HasCrudActions;
/**
* Model for the resource.
*
* @var string
*/
protected $model = Attribute::class;
/**
* The relations to eager load on every query.
*
* @var array
*/
protected $with = ['values'];
/**
* Label of the resource.
*
* @var string
*/
protected $label = 'attribute::admin.attribute';
/**
* View path of the resource.
*
* @var string
*/
protected $viewPath = 'attribute::admin.attributes';
/**
* Form requests for the resource.
*
* @var array
*/
protected $validation = SaveAttributeRequest::class;
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Modules\Attribute\Http\Controllers\Admin;
use Modules\Admin\Traits\HasCrudActions;
use Modules\Attribute\Entities\AttributeSet;
use Modules\Attribute\Http\Requests\SaveAttributeSetRequest;
class AttributeSetController
{
use HasCrudActions;
/**
* Model for the resource.
*
* @var string
*/
protected $model = AttributeSet::class;
/**
* Label of the resource.
*
* @var string
*/
protected $label = 'attribute::attribute_sets.attribute_set';
/**
* View path of the resource.
*
* @var string
*/
protected $viewPath = 'attribute::admin.attribute_sets';
/**
* Form requests for the resource.
*
* @var array
*/
protected $validation = SaveAttributeSetRequest::class;
}

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']);
});
}
}