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