'required', ]; } public function mount ($model = null){ $this->host_groups_available = HostGroup::pluck('name', 'id')->toArray(); if (!empty($model)) { $host = Host::find($model); $this->model = $model; $this->hostname = $host->hostname; $this->host_groups = $host->hostGroups()->pluck('host_groups.id')->toArray(); $this->action = 'update'; } } public function store() { $validatedData = $this->validate(); $host = Host::create($validatedData); $host->hostGroups()->sync($this->host_groups); $this->dispatch('closeModal'); } public function update() { $validatedData = $this->validate(); $host = Host::find($this->model); if (!empty($host)) { $host->update($validatedData); $host->hostGroups()->sync($this->host_groups); } $this->dispatch('closeModal'); } public function render() { return view('livewire.host.form'); } }