isMethod('get')) { return []; } return [ 'name' => 'array', 'name.*' => 'required', 'body' => 'array', 'body.*' => 'required', 'short_body' => 'array', 'short_body.*' => 'required|max:300', 'price' => 'required|numeric|gt:price_discount', 'price_discount' => 'nullable', 'poster' => 'required|mimes:jpeg,png,jpg', 'brand_id' => 'required', 'measurement_id' => 'nullable|exists:measurements,id', 'category_id' => 'required|integer|exists:categories,id', 'colors' => 'array|required', 'colors.*.color_id' => 'nullable', 'colors.*.sizes' => 'nullable|array', 'colors.*.sizes.*.name' => 'required', 'colors.*.sizes.*.count' => 'required', 'colors.*.screens' => 'array|required', 'colors.*.screens.*.image' => 'required|mimes:jpeg,png,jpg', "calc" => [], 'popular' => 'nullable', 'leader_of_sales' => 'nullable', 'article_number' => 'required|unique:products,article_number' ]; } /** * @return mixed */ public function getColors() { return $this->get('colors'); } /** * @return string */ public function getPoster(): string { $folder = "uploads/posters/" . Carbon::now()->format('Y/m/d'); return Uploads::store($this->file('poster'), $folder); } /** * @return string */ public function getCalc(): string|null { if ($this->hasFile('calc')) { $folder = "uploads/calc/" . Carbon::now()->format('Y/m/d'); return Uploads::store($this->file('calc'), $folder); } return null; } public function getDataSheet() { if ($this->hasFile('data_sheet')) { $folder = "uploads/datasheet/" . Carbon::now()->format('Y/m/d'); return Uploads::store($this->file('data_sheet'), $folder); } return null; } /** * @return string */ public function getPosterThumb() { $image = $this->file('poster'); $tempPath = Uploads::store($image, 'temp', 'public'); $resizer = new ImageResize(); return $resizer->resize($tempPath, 322, 'posters', true); } /** * @return array */ public function getName(): array { return $this->get('name'); } /** * @return array */ public function getBody(): array { return $this->get('body'); } public function getPrice() { return $this->get('price'); } public function getPriceDiscount() { if ($this->get('price_discount') > 0) { return $this->get('price_discount'); } return 0; } public function getPriceCredit() { if ($this->get('price_credit') > 0) { return $this->get('price_credit'); } return null; } /** * @return mixed */ public function getCategoryID() { return $this->get('category_id'); } /** * @return string */ public function getSlug(): string { if ($this->get('slug') != 'null') { return (string) str_slug($this->get('slug')); } return (string) str_slug($this->get('name')['ru']); } /** * @return bool */ public function getPublished() { if ($this->get('published') == 'true') { return true; } return false; } /** * @return bool */ public function getAvailable() { if ($this->get('available') == 'true') { return true; } return false; } /** * @return int|null */ public function getBrandID() { if ($this->get('brand_id') != 0) { return (int) $this->get('brand_id'); } return null; } public function getMeasurementId() { if ($this->get('measurement_id') != 0) { return (int) $this->get('measurement_id'); } return null; } public function getPopular(): bool { return $this->get('popular'); } public function getLeaderOfSales(): bool { if ($this->has('leader_of_sales')) { if ($this->get('leader_of_sales') == 'true') { return true; } } return false; } }