setupTenantConnection(); } public function mount($type, $idx, $causal_id) { $this->type = $type; $this->idx = $idx; $this->causal_id = $causal_id; if ($this->causal_id != null && $this->causal_id != 0) { $c = \App\Models\Causal::findOrFail($this->causal_id); $ids = array_reverse($c->recursiveParent($c->parent_id, [$c->id])); foreach($ids as $ii => $i) { if ($ii == 0) { $this->level_1_id = $i; } if ($ii == 1) { $this->level_2_id = $i; } if ($ii == 2) { $this->level_3_id = $i; } } } } public function updatedLevel1Id() { $this->emit($this->emit, null, $this->idx); $this->level_2_id = 0; $this->level_2 = []; $this->level_3_id = 0; $this->level_3 = []; } public function updatedLevel2Id() { $this->emit($this->emit, null, $this->idx); $this->level_3_id = 0; $this->level_3 = []; } public function updatedLevel3Id() { $this->emit($this->emit, null, $this->idx); } public function render() { $reset = false; $visibilityFilter = function($query) { return $query; }; $courseFilter = function($query) { return $query; }; if ($this->show_hidden == false) { $visibilityFilter = function($query) { return $query->where('hidden', false); }; } if ($this->show_course_causals == false) { $courseFilter = function($query) { return $query->whereNotIn('name', ['PAGAMENTO CORSO', 'PAGAMENTO ISCRIZIONE']); }; } if ($this->level_1_id > 0) { $this->level_2 = \App\Models\Causal::where('parent_id', $this->level_1_id) ->where('type', $this->type) ->where(function($query) use ($visibilityFilter) { return $visibilityFilter($query); }) ->where(function($query) use ($courseFilter) { return $courseFilter($query); }) ->orderBy('name') ->get(); if (sizeof($this->level_2) == 0) { $this->emit($this->emit, $this->level_1_id, $this->idx); $reset = true; } } if ($this->level_2_id > 0) { $this->level_3 = \App\Models\Causal::where('parent_id', $this->level_2_id) ->where('type', $this->type) ->where(function($query) use ($visibilityFilter) { return $visibilityFilter($query); }) ->where(function($query) use ($courseFilter) { return $courseFilter($query); }) ->orderBy('name') ->get(); if (sizeof($this->level_3) == 0) { $this->emit($this->emit, $this->level_2_id, $this->idx); $reset = true; } } if ($this->level_3_id > 0) { $this->emit($this->emit, $this->level_3_id, $this->idx); $reset = true; } $this->level_1 = \App\Models\Causal::where('parent_id', null) ->where('type', $this->type) ->where(function($query) use ($visibilityFilter) { return $visibilityFilter($query); }) ->where(function($query) use ($courseFilter) { return $courseFilter($query); }) ->orderBy('name') ->get(); return view('livewire.causals'); } }