61 lines
1.3 KiB
PHP
61 lines
1.3 KiB
PHP
<?php
|
|
namespace App\Livewire\Maintenance;
|
|
|
|
use Livewire\Component;
|
|
use App\Models\Maintenance;
|
|
|
|
class Form extends Component
|
|
{
|
|
public $model;
|
|
public string $name = "";
|
|
public string $description = "";
|
|
public string $schedule = "";
|
|
|
|
public $action = 'store';
|
|
|
|
protected function rules()
|
|
{
|
|
return [
|
|
'name' => 'required',
|
|
'description' => 'required',
|
|
'schedule' => 'required',
|
|
];
|
|
}
|
|
|
|
public function mount ($model = null){
|
|
if (!empty($model)) {
|
|
$maintenance = Maintenance::find($model);
|
|
|
|
$this->model = $model;
|
|
|
|
$this->name = $maintenance->name;
|
|
$this->description = $maintenance->description;
|
|
$this->schedule = $maintenance->schedule;
|
|
|
|
$this->action = 'update';
|
|
}
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
$validatedData = $this->validate();
|
|
Maintenance::create($validatedData);
|
|
$this->dispatch('closeModal');
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$validatedData = $this->validate();
|
|
$maintenance = Maintenance::find($this->model);
|
|
if (!empty($maintenance)) {
|
|
$maintenance->update($validatedData);
|
|
}
|
|
$this->dispatch('closeModal');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.maintenance.form');
|
|
}
|
|
}
|