113 lines
2.4 KiB
PHP
Executable File
113 lines
2.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Requests\Dashboard\Category;
|
|
|
|
use App\Support\Uploads;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Request extends FormRequest
|
|
{
|
|
protected function prepareForValidation()
|
|
{
|
|
if (in_array($this->get('parent_id'), [0, '0', '', 'null', 'NULL'], true)) {
|
|
$this->merge(['parent_id' => null]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
if ($this->isMethod('get')) {
|
|
return [];
|
|
}
|
|
return [
|
|
'name' => 'required|array',
|
|
'name.*' => 'required|string',
|
|
'image' => 'nullable|mimes:jpg,jpeg,png',
|
|
'parent_id' => 'nullable|integer|exists:categories,id',
|
|
'brands' => 'nullable|array',
|
|
'position' => 'nullable|numeric'
|
|
];
|
|
}
|
|
|
|
public function getName(): array
|
|
{
|
|
return $this->get('name');
|
|
}
|
|
|
|
public function getSlug(): string
|
|
{
|
|
return Str::slug($this->get('name')['uz']);
|
|
}
|
|
|
|
public function getImage(): string
|
|
{
|
|
if ($this->hasFile('image')) {
|
|
if (env('FILESYSTEM_DISK') == 's3') {
|
|
$folder = "uploads/categories";
|
|
|
|
return Uploads::store($this->file('image'), $folder);
|
|
} else {
|
|
return Uploads::store($this->file('image'), 'uploads/categories', 'local');
|
|
}
|
|
} else {
|
|
return 'null';
|
|
}
|
|
}
|
|
|
|
public function getPublished()
|
|
{
|
|
if ($this->get('published') == 'true') {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getFilterPower()
|
|
{
|
|
if ($this->get('is_filter_power') == 'true') {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getCredit()
|
|
{
|
|
if ($this->get('credit') == 'true') {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getParentId()
|
|
{
|
|
if ((int) $this->get('parent_id') > 0) {
|
|
return (int) $this->get('parent_id');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getPosition(): int
|
|
{
|
|
return (int) $this->get('position');
|
|
}
|
|
|
|
public function getPopular(): bool
|
|
{
|
|
if ($this->get('popular') == 'false') {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|