47 lines
1.2 KiB
PHP
47 lines
1.2 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('Create Sparepart')]
|
|
class CreateSparepart 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'],
|
|
]);
|
|
|
|
$sparepart = new Model();
|
|
$sparepart->name = $this->name;
|
|
$sparepart->description = $this->description;
|
|
$sparepart->manufacturer_id = $this->manufacturer_id;
|
|
$sparepart->save();
|
|
|
|
return $this->redirectRoute('spareparts.show', $sparepart->id, navigate: true);
|
|
}
|
|
|
|
public function cancel(){
|
|
return $this->redirectRoute('spareparts.index', navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.sparepart.create', [
|
|
]);
|
|
}
|
|
}
|