name = $diet->name; $this->image = $diet->image; $this->duration = $diet->duration; $this->state = $diet->state; $this->type = $diet->type; $this->details = $diet->details; $this->days = $diet->daily_schedule; } public function render() { return view('livewire.diet.edit'); } public function dayUpdated($dayIndex, $data) { $this->days[$dayIndex] = $data; } public function showPreview() { $this->state = 'draft'; $this->publish(); } public function addToDrafts() { $this->state = 'draft'; $this->publish(); } public function makeCopy($day) { /* dd($day); */ $this->copyedDay = $day; } public function makePaste($copyToDay) { $data = $this->days[$this->copyedDay]; $this->dispatch( 'takePaste', day: $copyToDay, data: $data )->to('diet.day-edit'); } public function publish(): void { $this->validate(); $diet = $this->diet; $diet->name = $this->name; /* $diet->image = $this->image->store('diets', 'public'); */ $diet->image = ! is_string($this->image) ? $this->image->store('plans') : $this->image; $diet->duration = $this->duration; $diet->state = $this->state; $diet->type = $this->type; $diet->details = $this->details; $diet->daily_schedule = $this->days; $diet->save(); $this->redirectRoute('diet.show', $diet); /* $user = Auth::user(); */ /* $user->author_of_diets()->attach($diet->id); */ } protected function rules() { return [ 'name' => 'required|min:3', /* 'image' => 'required|image|max:2048', */ 'duration' => 'required|numeric|min:7', 'state' => 'required|in:active,draft,archived', 'type' => ['required', 'array:meat,veg,corb,alko', 'min:1'], 'details' => 'required|min:3', ]; } }