47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Printer;
|
|
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
use App\Models\Printer as Model;
|
|
use Livewire\Attributes\title;
|
|
|
|
#[title('Create Printertype')]
|
|
class CreatePrinter extends Component
|
|
{
|
|
public Model $printer ;
|
|
|
|
public string $name = '';
|
|
public string $description = '';
|
|
public int $printertype_id = 0;
|
|
|
|
|
|
#[Validate('required')]
|
|
public function save(){
|
|
$this->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'description' => ['nullable', 'string', 'max:255'],
|
|
'printertype_id' => ['required', 'integer'],
|
|
]);
|
|
|
|
$printer = new Model();
|
|
$printer->name = $this->name;
|
|
$printer->description = $this->description;
|
|
$printer->printertype_id = $this->printertype_id;
|
|
$printer->save();
|
|
|
|
return $this->redirectRoute('printers.show', $printer->id, navigate: true);
|
|
}
|
|
|
|
public function cancel(){
|
|
return $this->redirectRoute('printers.index', navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.printer.create', [
|
|
]);
|
|
}
|
|
}
|