LAR_Maintenance/app/Livewire/HostGroup/Form.php
2024-09-25 22:09:13 +02:00

55 lines
1.1 KiB
PHP

<?php
namespace App\Livewire\HostGroup;
use Livewire\Component;
use App\Models\HostGroup;
class Form extends Component
{
public $model;
public string $name;
public $action = 'store';
protected function rules()
{
return [
'name' => 'required',
];
}
public function mount ($model = null){
if (!empty($model)) {
$hostGroup = HostGroup::find($model);
$this->model = $model;
$this->name = $hostGroup->name;
$this->action = 'update';
}
}
public function store()
{
$validatedData = $this->validate();
HostGroup::create($validatedData);
$this->dispatch('closeModal');
}
public function update()
{
$validatedData = $this->validate();
$hostGroup = HostGroup::find($this->model);
if (!empty($hostGroup)) {
$hostGroup->update($validatedData);
}
$this->dispatch('closeModal');
}
public function render()
{
return view('livewire.host-group.form');
}
}