'required|min:3', 'image' => 'required|image|max:2048', 'duration' => 'required|numeric|min:7', 'state' => 'required|in:draft,active,inactive', 'type' => ['required', 'array:slim,fit,wellness,behavior', 'min:1'], 'details' => 'required|min:3', 'packets_count' => 'required|in:1,3', 'packet1_options.short' => 'required|string|min:3', 'packet1_options.price' => 'required|numeric|min:1', 'packet1_options.description' => 'required|string|min:3', 'packet1_options.items' => 'required|array|min:1', ]; if($this->packets_count === 3) { $rules['packet2_options.short'] = 'required|string|min:3'; $rules['packet2_options.price'] = 'required|numeric|min:1'; $rules['packet2_options.description'] = 'required|string|min:3'; $rules['packet2_options.items'] = 'required|array|min:1'; $rules['packet3_options.short'] = 'required|string|min:3'; $rules['packet3_options.price'] = 'required|numeric|min:1'; $rules['packet3_options.description'] = 'required|string|min:3'; $rules['packet3_options.items'] = 'required|array|min:1'; } return $rules; } public function render() { return view('livewire.plan.create'); } public function addPacketOption($options_type, $options_type_input) { $this->$options_type['short'] = $this->$options_type_input['short']; $this->$options_type['price'] = $this->$options_type_input['price']; $this->$options_type['description'] = $this->$options_type_input['description']; $this->$options_type['items'][] = $this->input_items_1; $this->$options_type['items'][] = $this->input_items_2; $this->$options_type['items'][] = $this->input_items_3; $this->reset('input_items_1'); $this->reset('input_items_2'); $this->reset('input_items_3'); } public function publish() { $this->validate(); $plan = new Plan(); $this->name = $plan->name; $this->image = $plan->image->store('plans', 'public'); $this->duration = $plan->duration; $this->state = $plan->state; $this->details = $plan->details; $this->packets_count = $plan->packets_count; $this->type = json_encode($plan->type); $this->packet1_options = json_encode($plan->packet1_options); $this->packet2_options = json_encode($plan->packet2_options); $this->packet3_options = json_encode($plan->packet3_options); $this->plan->saveOrFail(); $user = Auth::user(); $user->author_of_plans()->attach($plan->id); return redirect()->route('plan.show', $plan->id); } public function addToDrafts() { $this->state = "draft"; $this->publish(); } public function showPreview() { $this->state = "inactive"; $this->publish(); } }