level_1_id > 0) { $this->level_2 = \App\Models\Category::where('parent_id', $this->level_1_id)->orderBy('name')->get(); if (sizeof($this->level_2) == 0) { $this->emit('storeCategoryWithID', $this->level_1_id); $reset = true; } } if ($this->level_2_id > 0) { $this->level_3 = \App\Models\Category::where('parent_id', $this->level_2_id)->orderBy('name')->get(); if (sizeof($this->level_3) == 0) { $this->emit('storeCategoryWithID', $this->level_2_id); $reset = true; } } if ($this->level_3_id > 0) { $this->emit('storeCategoryWithID', $this->level_3_id); $reset = true; } $this->level_1 = \App\Models\Category::where('parent_id', null)->orderBy('name')->get(); if ($reset) { $this->level_1_id = 0; $this->level_2_id = 0; $this->level_3_id = 0; $this->level_2 = []; $this->level_3 = []; } return view('livewire.categories'); } }