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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user