Add Printers and Printertypes modules with CRUD functionality, migrations, and UI components.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Printer;
|
||||
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use App\Models\Printer as Model;
|
||||
use Livewire\Attributes\title;
|
||||
|
||||
#[title('Edit Printer')]
|
||||
class EditPrinter 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'],
|
||||
]);
|
||||
|
||||
$this->printertype->update([
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'printertype_id' => $this->printertype_id,
|
||||
]);
|
||||
|
||||
return $this->redirectRoute('printers.show', $this->printer->id, navigate: true);
|
||||
}
|
||||
|
||||
public function cancel(){
|
||||
return $this->redirectRoute('printers.index', navigate: true);
|
||||
}
|
||||
|
||||
public function mount(Model $printer){
|
||||
$this->printer = $printer;
|
||||
$this->name = $printer->name;
|
||||
$this->description = $printer->description;
|
||||
$this->printertype_id = $printer->printertype_id;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.printer.create', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user