53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Sparepart;
|
|
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
use App\Models\Sparepart as Model;
|
|
use Livewire\Attributes\title;
|
|
|
|
#[title('Edit Sparepart')]
|
|
class EditSparepart extends Component
|
|
{
|
|
public Model $sparepart ;
|
|
|
|
public string $name = '';
|
|
public string $description = '';
|
|
public int $manufacturer_id = 0;
|
|
|
|
#[Validate('required')]
|
|
public function save(){
|
|
$this->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'description' => ['nullable', 'string', 'max:255'],
|
|
'manufacturer_id' => ['required', 'integer'],
|
|
]);
|
|
|
|
$this->sparepart->update([
|
|
'name' => $this->name,
|
|
'description' => $this->description,
|
|
'manufacturer_id' => $this->manufacturer_id
|
|
]);
|
|
|
|
return $this->redirectRoute('spareparts.show', $this->sparepart->id, navigate: true);
|
|
}
|
|
|
|
public function cancel(){
|
|
return $this->redirectRoute('spareparts.index', navigate: true);
|
|
}
|
|
|
|
public function mount(Model $sparepart){
|
|
$this->sparepart = $sparepart;
|
|
$this->name = $sparepart->name;
|
|
$this->description = $sparepart->description;
|
|
$this->manufacturer_id = $sparepart->manufacturer_id;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.sparepart.create', [
|
|
]);
|
|
}
|
|
}
|