Add Printers and Printertypes modules with CRUD functionality, migrations, and UI components.

This commit is contained in:
2026-01-24 11:23:37 +01:00
parent 563b0e750e
commit fd61f14ffe
25 changed files with 1017 additions and 4 deletions
+46
View File
@@ -0,0 +1,46 @@
<?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', [
]);
}
}
+52
View File
@@ -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', [
]);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Livewire\Printer;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use App\Models\Printer as Model;
use App\Models\Manufacturer as Manufacturer;
use Livewire\WithPagination;
use Livewire\Attributes\title;
#[title('Printer')]
class Printer extends Component
{
use WithPagination;
public Model $printer ;
public $search = '';
public function create(){
return $this->redirectRoute('printers.create', navigate: true);
}
public function show($id){
return $this->redirectRoute('printers.show', $id);
}
public function edit($id){
return $this->redirectRoute('printers.edit', $id);
}
public function delete($id){
@Auth::check();
Model::destroy($id);
}
public function render()
{
return view('livewire.printer.index', [
'printers' => Model::search('name', $this->search)->paginate(25)
]);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Livewire\Printer;
use Livewire\Component;
use App\Models\Printer as Model;
use Livewire\Attributes\title;
#[title('Show Printer')]
class ShowPrinter extends Component
{
public Model $printer ;
public function back(){
return redirect()->route('printers.index');
}
public function edit($id){
return redirect()->route('printers.edit', $id);
}
public function render()
{
return view('livewire.printer.show', [
]);
}
}
@@ -0,0 +1,58 @@
<?php
namespace App\Livewire\Printertype;
use Livewire\Attributes\Validate;
use Livewire\Component;
use App\Models\Printertype as Model;
use Livewire\Attributes\title;
#[title('Create Printertype')]
class CreatePrintertype extends Component
{
public Model $printertype ;
public string $name = '';
public string $description = '';
public int $manufacturer_id = 0;
public int $temp_max = 0;
public int $bed_size_x = 0;
public int $bed_size_y = 0;
public float $price = 0;
#[Validate('required')]
public function save(){
$this->validate([
'name' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:255'],
'manufacturer_id' => ['required', 'integer'],
'temp_max' => ['required', 'integer'],
'bed_size_x' => ['nullable', 'numeric'],
'bed_size_y' => ['nullable', 'numeric'],
'price' => ['nullable', 'numeric']
]);
$printertype = new Model();
$printertype->name = $this->name;
$printertype->description = $this->description;
$printertype->manufacturer_id = $this->manufacturer_id;
$printertype->temp_max = $this->temp_max;
$printertype->bed_size_x = $this->bed_size_x;
$printertype->bed_size_y = $this->bed_size_y;
$printertype->price = $this->price;
$printertype->save();
return $this->redirectRoute('printertypes.show', $printertype->id, navigate: true);
}
public function cancel(){
return $this->redirectRoute('printertypes.index', navigate: true);
}
public function render()
{
return view('livewire.printertype.create', [
]);
}
}
@@ -0,0 +1,68 @@
<?php
namespace App\Livewire\Printertype;
use Livewire\Attributes\Validate;
use Livewire\Component;
use App\Models\Printertype as Model;
use Livewire\Attributes\title;
#[title('Edit Printertype')]
class EditPrintertype extends Component
{
public Model $printertype ;
public string $name = '';
public string $description = '';
public int $manufacturer_id = 0;
public int $temp_max = 0;
public int $bed_size_x = 0;
public int $bed_size_y = 0;
public float $price = 0;
#[Validate('required')]
public function save(){
$this->validate([
'name' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:255'],
'manufacturer_id' => ['required', 'integer'],
'temp_max' => ['required', 'integer'],
'bed_size_x' => ['nullable', 'numeric'],
'bed_size_y' => ['nullable', 'numeric'],
'price' => ['nullable', 'numeric']
]);
$this->printertype->update([
'name' => $this->name,
'description' => $this->description,
'manufacturer_id' => $this->manufacturer_id,
'temp_max' => $this->temp_max,
'bed_size_x' => $this->bed_size_x,
'bed_size_y' => $this->bed_size_y,
'price' => $this->price
]);
return $this->redirectRoute('printertypes.show', $this->printertype->id, navigate: true);
}
public function cancel(){
return $this->redirectRoute('printertypes.index', navigate: true);
}
public function mount(Model $printertype){
$this->printertype = $printertype;
$this->name = $printertype->name;
$this->description = $printertype->description;
$this->manufacturer_id = $printertype->manufacturer_id;
$this->temp_max = $printertype->temp_max;
$this->bed_size_x = $printertype->bed_size_x;
$this->bed_size_y = $printertype->bed_size_y;
$this->price = $printertype->price;
}
public function render()
{
return view('livewire.printertype.create', [
]);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Livewire\Printertype;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use App\Models\Printertype as Model;
use App\Models\Manufacturer as Manufacturer;
use Livewire\WithPagination;
use Livewire\Attributes\title;
#[title('Printertypes')]
class Printertype extends Component
{
use WithPagination;
public Model $printertype ;
public $search = '';
public function create(){
return $this->redirectRoute('printertypes.create', navigate: true);
}
public function show($id){
return $this->redirectRoute('printertypes.show', $id);
}
public function edit($id){
return $this->redirectRoute('printertypes.edit', $id);
}
public function delete($id){
@Auth::check();
Model::destroy($id);
}
public function render()
{
return view('livewire.printertype.index', [
'printertypes' => Model::search('name', $this->search)->paginate(25)
]);
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Livewire\Printertype;
use Livewire\Component;
use App\Models\Printertype as Model;
use Livewire\Attributes\title;
#[title('Show Printertype')]
class ShowPrintertype extends Component
{
public Model $printertype ;
public function back(){
return redirect()->route('printertypes.index');
}
public function edit($id){
return redirect()->route('printertypes.edit', $id);
}
public function render()
{
return view('livewire.printertype.show', [
]);
}
}
+1 -1
View File
@@ -38,7 +38,7 @@ class EditSparepart extends Component
}
public function mount(Model $sparepart){
$this->filament = $sparepart;
$this->sparepart = $sparepart;
$this->name = $sparepart->name;
$this->description = $sparepart->description;
$this->manufacturer_id = $sparepart->manufacturer_id;
+1 -1
View File
@@ -6,7 +6,7 @@ use Livewire\Component;
use App\Models\Sparepart as Model;
use Livewire\Attributes\title;
#[title('Show Filament')]
#[title('Show Sparepart')]
class ShowSparepart extends Component
{
+1 -1
View File
@@ -9,7 +9,7 @@ use App\Models\Manufacturer as Manufacturer;
use Livewire\WithPagination;
use Livewire\Attributes\title;
#[title('Filaments')]
#[title('Spareparts')]
class Sparepart extends Component
{
use WithPagination;