Refactored Manufacturer and Buildplate Livewire components. Introduced create, edit, and show components with route-based navigation. Updated views for consistency and cleaned up unused modals and legacy code. Adjusted styles and table layouts.
This commit is contained in:
@@ -4,10 +4,7 @@ namespace App\Livewire\Buildplate;
|
||||
|
||||
use App\Models\Buildplate as BuildplateModel;
|
||||
use App\Models\Manufacturer as Manufacturer;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
@@ -16,118 +13,25 @@ class Buildplate extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
#[Validate('required')]
|
||||
public $name = '';
|
||||
public $description = '';
|
||||
public $manufacturer_id = '';
|
||||
public $temp_max = '';
|
||||
public $amount = '';
|
||||
|
||||
public $search ='';
|
||||
|
||||
// Edit Modal + Query
|
||||
public $editquery = '';
|
||||
|
||||
public $editid = '';
|
||||
public $deleteid = '';
|
||||
|
||||
public function create() {
|
||||
@Auth::check();
|
||||
|
||||
|
||||
// Validate
|
||||
$this->validate();
|
||||
|
||||
$buildplate = new BuildplateModel();
|
||||
$buildplate->name = $this->name;
|
||||
$buildplate->description = $this->description;
|
||||
$buildplate->manufacturer_id = $this->manufacturer_id;
|
||||
$buildplate->temp_max = $this->temp_max;
|
||||
$buildplate->amount = $this->amount;
|
||||
$buildplate->save();
|
||||
|
||||
// Clear the form
|
||||
$this->resetInputFields();
|
||||
|
||||
// Close the modal
|
||||
Flux::modal('createModal')->close();
|
||||
public function create(){
|
||||
return $this->redirectRoute('buildplate.create', navigate: true);
|
||||
}
|
||||
|
||||
public function edit($buildplateid) {
|
||||
@Auth::check();
|
||||
|
||||
$editid = $buildplateid;
|
||||
$this->editid = $editid;
|
||||
|
||||
$buildplate = BuildplateModel::findOrFail($editid);
|
||||
|
||||
$this->name = $buildplate->name;
|
||||
$this->description = $buildplate->description;
|
||||
$this->manufacturer_id = $buildplate->manufacturer_id;
|
||||
$this->temp_max = $buildplate->temp_max;
|
||||
$this->amount = $buildplate->amount;
|
||||
|
||||
Flux::modal('editModal')->show();
|
||||
public function edit($id){
|
||||
return $this->redirectRoute('buildplate.edit', $id, navigate: true);
|
||||
}
|
||||
|
||||
public function save($editid) {
|
||||
@Auth::check();
|
||||
|
||||
$buildplate = BuildplateModel::findOrFail($editid);
|
||||
$buildplate->name = $this->name;
|
||||
$buildplate->description = $this->description;
|
||||
$buildplate->manufactuerer_id = $this->manufacturer_id;
|
||||
$buildplate->temp_max = $this->temp_max;
|
||||
$buildplate->amount = $this->amount;
|
||||
$buildplate->save();
|
||||
|
||||
$this->resetInputFields();
|
||||
|
||||
Flux::modal('editModal')->close();
|
||||
public function show($id){
|
||||
return $this->redirectRoute('buildplate.show', $id, navigate: true);
|
||||
}
|
||||
|
||||
public function deleteModal($buildplateid) {
|
||||
@Auth::check();
|
||||
|
||||
$deleteid = $buildplateid;
|
||||
$this->deleteid = $deleteid;
|
||||
|
||||
$buildplate = BuildplateModel::findOrFail($deleteid);
|
||||
$this->name = $buildplate->name;
|
||||
$this->description = $buildplate->description;
|
||||
$this->manufacturer_id = $buildplate->manufacturer_id;
|
||||
$this->temp_max = $buildplate->temp_max;
|
||||
$this->amount = $buildplate->amount;
|
||||
|
||||
Flux::modal('deleteModal')->show();
|
||||
}
|
||||
|
||||
public function delete($deleteid) {
|
||||
@Auth::check();
|
||||
|
||||
$buildplate = BuildplateModel::findOrFail($deleteid)->delete();
|
||||
|
||||
$this->deleteid = $deleteid;
|
||||
Flux::modal('deleteModal')->close();
|
||||
|
||||
// Clear the form
|
||||
$this->resetInputFields();
|
||||
}
|
||||
|
||||
public function cancel() {
|
||||
$this->resetInputFields();
|
||||
Flux::modals()->close();
|
||||
}
|
||||
|
||||
public function resetInputFields() {
|
||||
$this->reset(['name', 'description', 'manufacturer_id', 'temp_max', 'amount', 'deleteid', 'editid']);;
|
||||
public function delete($id){
|
||||
BuildplateModel::destroy($id);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.buildplate.index', [
|
||||
'buildplates' => BuildplateModel::search('name', $this->search)->paginate(20),
|
||||
'manufacturers' => Manufacturer::all(),
|
||||
'buildplates' => BuildplateModel::search('name', $this->search)->paginate(10),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Buildplate;
|
||||
|
||||
use App\Models\Buildplate as Model;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
#[title('Buildplates')]
|
||||
class CreateBuildplate extends Component
|
||||
{
|
||||
public Model $buildplate ;
|
||||
public string $name = '';
|
||||
public string $description = '';
|
||||
public int $manufacturer_id = 0;
|
||||
public string $temp_max = '';
|
||||
|
||||
#[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']
|
||||
]);
|
||||
|
||||
$buildplate = new Model();
|
||||
$buildplate->name = $this->name;
|
||||
$buildplate->description = $this->description;
|
||||
$buildplate->manufacturer_id = $this->manufacturer_id;
|
||||
$buildplate->temp_max = $this->temp_max;
|
||||
$buildplate->save();
|
||||
|
||||
return $this->redirectRoute('buildplate.show', $buildplate->id , navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.buildplate.create', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Buildplate;
|
||||
|
||||
use App\Models\Buildplate as Model;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Component;
|
||||
|
||||
#[title('Buildplates')]
|
||||
class EditBuildplate extends Component
|
||||
{
|
||||
public Model $buildplate ;
|
||||
public string $name = '';
|
||||
public string $description = '';
|
||||
public int $manufacturer_id = 0;
|
||||
public string $temp_max = '';
|
||||
|
||||
public function mount(Model $buildplate){
|
||||
$this->buildplate = $buildplate;
|
||||
$this->name = $buildplate->name;
|
||||
$this->description = $buildplate->description;
|
||||
$this->manufacturer_id = $buildplate->manufacturer_id;
|
||||
$this->temp_max = $buildplate->temp_max;
|
||||
}
|
||||
|
||||
public function save(){
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string', 'max:255'],
|
||||
'manufacturer_id' => ['required', 'integer'],
|
||||
'temp_max' => ['required', 'integer']
|
||||
]);
|
||||
|
||||
$this->buildplate->update([
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'manufacturer_id' => $this->manufacturer_id,
|
||||
'temp_max' => $this->temp_max
|
||||
]);
|
||||
return $this->redirectRoute('livewire.buildplate.show', $this->buildplate->id, navigate: true);
|
||||
}
|
||||
public function cancel(){
|
||||
return $this->redirectRoute('buildplate.index', navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.buildplate.edit', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Buildplate;
|
||||
|
||||
use App\Models\Buildplate as Model;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Component;
|
||||
|
||||
#[title('Buildplates')]
|
||||
class ShowBuildplate extends Component
|
||||
{
|
||||
public Model $buildplate ;
|
||||
|
||||
public function back(){
|
||||
return $this->redirectRoute('buildplate.index', navigate: true);
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
return $this->redirectRoute('buildplate.edit', $id, navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.buildplate.show', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Livewire\Color;
|
||||
|
||||
use App\Models\Color as Model;
|
||||
use Livewire\Attributes\title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
#[title('Colors')]
|
||||
@@ -15,6 +16,7 @@ class CreateColor extends Component
|
||||
public string $name = '';
|
||||
public string $hex = '';
|
||||
|
||||
#[Validate('required')]
|
||||
public function save(){
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Manufacturer;
|
||||
|
||||
use App\Models\Manufacturer as Model;
|
||||
use Livewire\Attributes\title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
#[title('Manufacturer List')]
|
||||
class CreateManufacturer extends Component{
|
||||
|
||||
public Model $manufacturer ;
|
||||
public string $name = '';
|
||||
public string $description = '';
|
||||
public string $website = '';
|
||||
|
||||
#[Validate('required')]
|
||||
public function save(){
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'website' => ['nullable', 'string', 'max:255']
|
||||
]);
|
||||
|
||||
$manufacturer = new Model();
|
||||
$manufacturer->name = $this->name;
|
||||
$manufacturer->description = $this->description;
|
||||
$manufacturer->website = $this->website;
|
||||
$manufacturer->save();
|
||||
|
||||
return redirect()->route('manufacturer.index');
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
|
||||
return view('livewire.manufacturer.create', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Manufacturer;
|
||||
|
||||
use App\Models\Manufacturer as Model;
|
||||
use Livewire\Attributes\title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
#[title('Manufacturer List')]
|
||||
class EditManufacturer extends Component{
|
||||
|
||||
public Model $manufacturer ;
|
||||
public string $name = '';
|
||||
public string $description = '';
|
||||
public string $website = '';
|
||||
|
||||
public function mount(Model $manufacturer){
|
||||
$this->manufacturer = $manufacturer;
|
||||
$this->name = $manufacturer->name;
|
||||
$this->description = $manufacturer->description;
|
||||
$this->website = $manufacturer->website;
|
||||
}
|
||||
|
||||
#[Validate('required')]
|
||||
public function save(){
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'website' => ['nullable', 'string', 'max:255']
|
||||
]);
|
||||
|
||||
$this->manufacturer->update([
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'website' => $this->website
|
||||
]);
|
||||
|
||||
return $this->redirectRoute('manufacturer.show', $this->manufacturer->id, navigate: true);
|
||||
}
|
||||
|
||||
public function cancel(){
|
||||
return $this->redirectRoute('manufacturer.index', navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
return view('livewire.manufacturer.edit', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,7 @@
|
||||
namespace App\Livewire\Manufacturer;
|
||||
|
||||
use App\Models\Manufacturer as Model;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
@@ -14,93 +11,19 @@ use Livewire\WithPagination;
|
||||
class Manufacturer extends Component{
|
||||
use WithPagination;
|
||||
|
||||
#[Validate('required')]
|
||||
public $name = '';
|
||||
|
||||
public $description = '';
|
||||
public $website = '';
|
||||
|
||||
public $search ='';
|
||||
|
||||
public $editid = '';
|
||||
public $deleteid = '';
|
||||
|
||||
public function create() {
|
||||
@Auth::check();
|
||||
|
||||
|
||||
// Validate
|
||||
$this->validate();
|
||||
|
||||
$manufacturer = new Model();
|
||||
$manufacturer->name = $this->name;
|
||||
$manufacturer->description = $this->description;
|
||||
$manufacturer->website = $this->website;
|
||||
$manufacturer->save();
|
||||
|
||||
// Clear the form
|
||||
$this->resetInputFields();
|
||||
|
||||
// Close the modal
|
||||
Flux::modal('createModal')->close();
|
||||
public function create(){
|
||||
return $this->redirectRoute('manufacturer.create', navigate: true);
|
||||
}
|
||||
public function edit($manufacturerid) {
|
||||
@Auth::check();
|
||||
|
||||
$editid = $manufacturerid;
|
||||
$this->editid = $editid;
|
||||
|
||||
$manufacturer = Model::findOrFail($editid);
|
||||
|
||||
$this->name = $manufacturer->name;
|
||||
$this->description = $manufacturer->description;
|
||||
$this->website = $manufacturer->website;
|
||||
|
||||
Flux::modal('editModal')->show();
|
||||
public function edit($id){
|
||||
return $this->redirectRoute('manufacturer.edit', $id, navigate: true);
|
||||
}
|
||||
public function save($editid) {
|
||||
@Auth::check();
|
||||
|
||||
$manufacturer = Model::findOrFail($editid);
|
||||
$manufacturer->name = $this->name;
|
||||
$manufacturer->description = $this->description;
|
||||
$manufacturer->website = $this->website;
|
||||
$manufacturer->save();
|
||||
|
||||
$this->resetInputFields();
|
||||
|
||||
Flux::modal('editModal')->close();
|
||||
public function show($id){
|
||||
return $this->redirectRoute('manufacturer.show', $id, navigate: true);
|
||||
}
|
||||
public function deleteModal($manufacturerid) {
|
||||
@Auth::check();
|
||||
|
||||
$deleteid = $manufacturerid;
|
||||
$this->deleteid = $deleteid;
|
||||
|
||||
$manufacturer = Model::findOrFail($deleteid);
|
||||
$this->name = $manufacturer->name;
|
||||
$this->description = $manufacturer->description;
|
||||
$this->website = $manufacturer->website;
|
||||
|
||||
Flux::modal('deleteModal')->show();
|
||||
}
|
||||
public function delete($deleteid) {
|
||||
@Auth::check();
|
||||
|
||||
$manufacturer = Model::findOrFail($deleteid)->delete();
|
||||
|
||||
$this->deleteid = $deleteid;
|
||||
Flux::modal('deleteModal')->close();
|
||||
|
||||
// Clear the form
|
||||
$this->resetInputFields();
|
||||
}
|
||||
public function cancel() {
|
||||
$this->resetInputFields();
|
||||
Flux::modals()->close();
|
||||
}
|
||||
public function resetInputFields() {
|
||||
$this->reset(['name', 'description', 'website', 'deleteid', 'editid']);
|
||||
public function delete($id){
|
||||
Model::destroy($id);
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Manufacturer;
|
||||
|
||||
use App\Models\Manufacturer as Model;
|
||||
use Livewire\Attributes\title;
|
||||
use Livewire\Component;
|
||||
|
||||
#[title('Manufacturer List')]
|
||||
class ShowManufacturer extends Component{
|
||||
|
||||
public Model $manufacturer ;
|
||||
|
||||
public function edit($id){
|
||||
return $this->redirectRoute('manufacturer.edit', $id, navigate: true);
|
||||
}
|
||||
public function back(){
|
||||
return $this->redirectRoute('manufacturer.index', navigate: true);
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
|
||||
return view('livewire.manufacturer.show', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user