| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- use App\Http\Middleware\TenantMiddleware;
- class Categories extends Component
- {
- public $level_1 = [];
- public $level_2 = [];
- public $level_3 = [];
- public $level_1_id = 0;
- public $level_2_id = 0;
- public $level_3_id = 0;
- public function boot()
- {
- app(TenantMiddleware::class)->setupTenantConnection();
- }
- public function render()
- {
- $this->emit('hideMsg');
- $reset = false;
- if ($this->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');
- }
- }
|