Refactored Filament Livewire components and views. Introduced separate CreateFilament component with route-based navigation. Simplified and cleaned up code by removing legacy modals and unused properties. Updated migrations, table layouts, and styles for consistency.

This commit is contained in:
2025-12-15 01:20:04 +01:00
parent 4759df9077
commit c7671b93b1
15 changed files with 461 additions and 645 deletions
+6 -107
View File
@@ -18,127 +18,26 @@ class Filament extends Component
{
use WithPagination;
#[Validate('required')]
public $name = '';
public $description = '';
public $diameter = '1.75';
public $color_id = '';
public $type_id = '';
public $manufacturer_id = '';
public $weight = '1000';
public $finish = 'Basic';
public $price = '0';
public $stock = '0';
public Model $filament ;
public $search = '';
public $editid = '';
public $deleteid = '';
public function create() {
@Auth::check();
// Validate
$this->validate();
$filament = new Model();
$filament->name = $this->name;
$filament->description = $this->description;
$filament->diameter = $this->diameter;
$filament->color_id = $this->color_id;
$filament->filament_type_id = $this->type_id;
$filament->manufacturer_id = $this->manufacturer_id;
$filament->weight = $this->weight;
$filament->finish = $this->finish;
$filament->price = $this->price;
$filament->stock = $this->stock;
$filament->save();
// Clear the form
$this->resetInputFields();
// Close the modal
Flux::modal('createModal')->close();
}
public function save($editid) {
@Auth::check();
$filament = Model::findOrFail($editid);
$filament->name = $this->name;
$filament->description = $this->description;
$filament->diameter = $this->diameter;
$filament->color_id = $this->color_id;
$filament->filament_type_id = $this->type_id;
$filament->manufacturer_id = $this->manufacturer_id;
$filament->weight = $this->weight;
$filament->finish = $this->finish;
$filament->price = $this->price;
$filament->stock = $this->stock;
$filament->save();
$this->resetInputFields();
Flux::modal('editModal')->close();
}
public function deleteModal($filamentid) {
@Auth::check();
$deleteid = $filamentid;
$this->deleteid = $deleteid;
$filament = Model::findOrFail($deleteid);
$this->name = $filament->name;
$this->description = $filament->description;
$this->diameter = $filament->diameter;
$this->color_id = $filament->color_id;
$this->type_id = $filament->filament_type_id;
$this->manufacturer_id = $filament->manufacturer_id;
$this->weight = $filament->weight;
$this->finish = $filament->finish;
$this->price = $filament->price;
$this->stock = $filament->stock;
Flux::modal('deleteModal')->show();
}
public function delete($deleteid) {
@Auth::check();
$filament = 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', 'diameter', 'color_id', 'type_id', 'manufacturer_id', 'weight', 'price', 'finish', 'deleteid', 'editid']);
public function create(){
return $this->redirectRoute('filaments.create', navigate: true);
}
public function show($id){
return redirect()->route('filaments.show', $id);
return $this->redirectRoute('filaments.show', $id);
}
public function edit($id){
return redirect()->route('filaments.edit', $id);
return $this->redirectRoute('filaments.edit', $id);
}
public function render()
{
return view('livewire.filament.index', [
'filaments' => Model::search('name', $this->search)->paginate(50),
'colors' => Color::all(),
'manufacturers' => Manufacturer::all(),
'types' => Type::all()
'filaments' => Model::search('name', $this->search)->paginate(25)
]);
}
}