LAR_Maintenance/app/Livewire/MaintenanceHistory/Form.php

61 lines
1.4 KiB
PHP
Raw Normal View History

2024-07-31 15:04:33 +00:00
<?php
namespace App\Livewire\MaintenanceHistory;
use Livewire\Component;
use App\Models\MaintenanceHistory;
class Form extends Component
{
public $model;
public string $maintenance_id;
public string $start_at;
public string $finished_at;
public $action = 'store';
protected function rules()
{
return [
'maintenance_id' => 'required',
'start_at' => 'required',
'finished_at' => 'required',
];
}
public function mount ($model = null){
if (!empty($model)) {
$maintenance-history = MaintenanceHistory::find($model);
$this->model = $model;
$this->maintenance_id = $maintenance-history->maintenance_id;
$this->start_at = $maintenance-history->start_at;
$this->finished_at = $maintenance-history->finished_at;
$this->action = 'update';
}
}
public function store()
{
$validatedData = $this->validate();
MaintenanceHistory::create($validatedData);
$this->dispatch('closeModal');
}
public function update()
{
$validatedData = $this->validate();
$maintenance-history = MaintenanceHistory::find($this->model);
if (!empty($maintenance-history)) {
$maintenance-history->update($validatedData);
}
$this->dispatch('closeModal');
}
public function render()
{
return view('livewire.components.maintenance-history.form');
}
}