LAR_Maintenance/app/Livewire/Host/Form.php

55 lines
1.0 KiB
PHP

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