check(); } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation() { $this->merge([ 'slug' => Str::slug(strip_tags($this->name)), 'weight_variable' => $this->weight_variable ? true : false, 'star' => $this->star ? true : false, 'status' => $this->status ? true : false ]); $this->foodProductRules = ($this->product_type !== null) ? FoodProductRequest::rules() : []; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $rules = [ 'product_type' => 'sometimes|nullable|string|min:3|max:255', 'name' => 'required|string|min:3|max:255', 'brand' => 'sometimes|nullable|string|min:3|max:255', 'description' => 'required|string|min:15', 'picture' => 'sometimes|nullable|image|mimes:jpeg,png,jpg|max:2048|dimensions:max_width=' . config('theme.product_image_maxwidth') . ',max_height=' . config('theme.product_image_maxheight'), 'picture_large' => 'sometimes|nullable|image|mimes:jpeg,png,jpg|max:2048|dimensions:max_width=' . config('theme.product_image_large_maxwidth') . ',max_height=' . config('theme.product_image_large_maxheight'), 'price' => 'required|min:0|numeric', 'invoicing_unit' => 'sometimes|nullable|string|min:3|max:255', 'price_buy' => 'sometimes|nullable|min:0|numeric', 'tax_rate_id' => 'required|integer|exists:tax_rates,id', 'stock' => 'sometimes|nullable|integer', 'sell_unit' => 'sometimes|nullable|string|min:3|max:255', 'order_unit' => 'sometimes|nullable|string|min:3|max:255', 'weight' => 'sometimes|nullable|numeric', 'weight_unit' => 'sometimes|nullable|string|min:1|max:255', 'weight_variable' => 'required|boolean', 'reference' => 'sometimes|nullable|string|min:1|max:255', 'slug' => 'required|string|min:3|max:255', 'star' => 'required|boolean', 'status' => 'required|boolean', 'orderable_start' => 'sometimes|nullable|date', 'orderable_end' => 'sometimes|nullable|date', 'range_id' => 'required|integer|exists:ranges,id', 'margin' => 'sometimes|nullable|integer', ]; return \array_merge( $rules, $this->foodProductRules, ); } /** * Get custom attributes for validator errors. * * @return array */ public function attributes() { return [ 'product_type' => \trans('type du produit'), 'name' => \trans('nom du produit'), 'brand' => \trans('marque du produit'), 'description' => \trans('description du produit'), 'picture' => \trans('image du produit'), 'picture_large' => \trans('image laaaaarge du produit'), 'price' => \trans('prix du produit'), 'invoicing_unit' => \trans('unité de facturation du produit'), 'price_buy' => \trans('prix d\'achat du produit'), 'tax_rate_id' => \trans('taux d\'imposition du produit'), 'stock' => \trans('stock du produit'), 'sell_unit' => \trans('unité de vente du produit'), 'order_unit' => \trans('unité de commande du produit'), 'weight' => \trans('poids du produit'), 'weight_unit' => \trans('unité de poids du produit'), 'weight_variable' => \trans('poids variable du produit'), 'reference' => \trans('reference du produit'), 'slug' => \trans('slug du produit'), 'star' => \trans('mis en avant du produit'), 'status' => \trans('publication du produit'), 'orderable_start' => \trans('début de commande du produit'), 'orderable_end' => \trans('fin de commande du produit'), 'range_id' => \trans('gamme du produit'), 'margin' => \trans('margin du produit'), ]; } }