Add Printers and Printertypes modules with CRUD functionality, migrations, and UI components.
This commit is contained in:
@@ -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', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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', [
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user