check(); } /** * Prepare the data for validation. * * @return void * @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh */ protected function prepareForValidation() { $tabFour = array( 'id' => 0, 'name' => 'Four', 'url' => '/assets/images/four.png', 'time' => $this->time_cook0, 'temp' => $this->temp_cook0, 'status' => $this->is_activated0 ? true : false ); $tabFriteuse = array( 'id' => 1, 'name' => 'Friteuse', 'url' => '/assets/images/friteuse.png', 'time' => $this->time_cook1, 'temp' => $this->temp_cook1, 'status' => $this->is_activated1 ? true : false ); $tabPoele = array( 'id' => 2, 'name' => 'Poêle', 'url' => '/assets/images/poele.png', 'time' => $this->time_cook2, 'temp' => $this->temp_cook2, 'status' => $this->is_activated2 ? true : false ); $tabCocotte = array( 'id' => 3, 'name' => 'Cocotte', 'url' => '/assets/images/cocotte.png', 'time' => $this->time_cook3, 'temp' => $this->temp_cook3, 'status' => $this->is_activated3 ? true : false ); $tabPlancha = array( 'id' => 4, 'name' => 'Plancha', 'url' => '/assets/images/plancha.png', 'time' => $this->time_cook4, 'temp' => $this->temp_cook4, 'status' => $this->is_activated4 ? true : false ); $tabBainMarie = array( 'id' => 5, 'name' => 'Bain Marie', 'url' => '/assets/images/bainmarie.png', 'time' => $this->time_cook5, 'temp' => $this->temp_cook5, 'status' => $this->is_activated5 ? true : false ); $tabBarbecue = array( 'id' => 6, 'name' => 'Barbecue', 'url' => '/assets/images/barbecue.png', 'time' => $this->time_cook6, 'temp' => $this->temp_cook6, 'status' => $this->is_activated6 ? true : false ); $tabMicroOndes = array( 'id' => 7, 'name' => 'Micro Ondes', 'url' => '/assets/images/micro-onde.png', 'time' => $this->time_cook7, 'temp' => $this->temp_cook7, 'status' => $this->is_activated7 ? true : false ); $tabCasserole = array( 'id' => 8, 'name' => 'Casserole', 'url' => '/assets/images/casserole.png', 'time' => $this->time_cook8, 'temp' => $this->temp_cook8, 'status' => $this->is_activated8 ? true : false ); $tabCuisson = json_encode([ 'four' => $tabFour, 'friteuse' => $tabFriteuse, 'poele' => $tabPoele, 'cocotte' => $tabCocotte, 'plancha' => $tabPlancha, 'bainmarie' => $tabBainMarie, 'barbecue' => $tabBarbecue, 'microondes' => $tabMicroOndes, 'casserole' => $tabCasserole ]); $urlPlusProduit = ""; if ($this->pictogramme0) { $urlPlusProduit = "/assets/images/" . $this->pictogramme0->getClientOriginalName(); } $tabPlusProduit1 = array( 'id' => 0, 'name' => $this->content0, 'url' => $urlPlusProduit, ); $urlPlusProduit = ""; if ($this->pictogramme1) { $urlPlusProduit = "/assets/images/" . $this->pictogramme1->getClientOriginalName(); } $tabPlusProduit2 = array( 'id' => 1, 'name' => $this->content1, 'url' => $urlPlusProduit, ); $urlPlusProduit = ""; if ($this->pictogramme2) { $urlPlusProduit = "/assets/images/" . $this->pictogramme2->getClientOriginalName(); } $tabPlusProduit3 = array( 'id' => 2, 'name' => $this->content2, 'url' => $urlPlusProduit, ); $tabPlusProduit = json_encode([$tabPlusProduit1, $tabPlusProduit2, $tabPlusProduit3]); $this->merge([ 'slug' => Str::slug($this->name), 'gamme_id' => $this->is_food_service ? Gamme::where("slug->fr", "food-service")->firstOrFail()->id : $this->gamme_id, 'pictos' => $tabCuisson, 'plusproduit' => $tabPlusProduit, 'is_published' => $this->is_published ? true : false, 'is_on_top' => $this->is_on_top ? true : false, 'is_news' => $this->is_news ? true : false, 'is_food_service' => $this->is_food_service ? true : false, 'is_halal' => $this->is_halal ? true : false, ]); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'gamme_id' => 'required|exists:gammes,id', 'name' => 'required|max:255', 'slug' => 'required|unique:products', 'description' => 'required|min:20', 'picture' => 'required|image|mimes:png|max:1024|dimensions:width=509,height=509', 'alt_text_picture' => 'required|max:255', 'pictos' => 'sometimes|nullable', 'plusproduit' => 'sometimes|nullable', 'pictogramme0' => 'nullable|image|mimes:png|max:1024|dimensions:width=141,height=100', 'pictogramme1' => 'nullable|image|mimes:png|max:1024|dimensions:width=141,height=100', 'pictogramme2' => 'nullable|image|mimes:png|max:1024|dimensions:width=141,height=100', 'is_published' => 'nullable|boolean', 'is_on_top' => 'nullable|boolean', 'is_news' => 'nullable|boolean', 'is_food_service' => 'nullable|boolean', 'is_halal' => 'nullable|boolean', ]; } /** * Get custom messages for validator errors. * * @return array */ public function messages() { return []; } /** * Get custom attributes for validator errors. * * @return array */ public function attributes() { return [ 'slug' => trans('libellé') ]; } }