diff --git a/app/Livewire/Extruder/CreateExtruder.php b/app/Livewire/Extruder/CreateExtruder.php index e653439..cb995dd 100644 --- a/app/Livewire/Extruder/CreateExtruder.php +++ b/app/Livewire/Extruder/CreateExtruder.php @@ -38,6 +38,10 @@ class CreateExtruder extends Component return $this->redirectRoute('extruder.show', $extruder->id , navigate: true); } + public function cancel(){ + return $this->redirectRoute('extruder.index', navigate: true); + } + public function render() { return view('livewire.extruder.create', [ diff --git a/app/Livewire/Filament/CreateFilament.php b/app/Livewire/Filament/CreateFilament.php index 3a96aaa..a0a8f5b 100644 --- a/app/Livewire/Filament/CreateFilament.php +++ b/app/Livewire/Filament/CreateFilament.php @@ -2,28 +2,65 @@ namespace App\Livewire\Filament; +use Livewire\Attributes\Validate; use Livewire\Component; use App\Models\Filament as Model; -use App\Models\Manufacturer; -use Livewire\WithPagination; use Livewire\Attributes\title; -#[title('Show Filament')] +#[title('Create Filament')] class CreateFilament extends Component { - public Model $filament ; - public function back(){ - return redirect()->route('filaments.index'); + public string $name = ''; + public string $description = ''; + public int $color_id = 0; + public int $manufacturer_id = 0; + public int $filament_type_id = 0; + public int $weight = 1000; + public string $diameter = '1.75'; + public float $price = 0; + public int $temp_min = 0; + public int $temp_max = 0; + + #[Validate('required')] + public function save(){ + $this->validate([ + 'name' => ['required', 'string', 'max:255'], + 'description' => ['nullable', 'string', 'max:255'], + 'color_id' => ['required', 'integer'], + 'manufacturer_id' => ['required', 'integer'], + 'filament_type_id' => ['required', 'integer'], + 'weight' => ['required', 'integer'], + 'diameter' => ['required', 'string', 'max:4'], + 'price' => ['required', 'numeric'], + 'temp_min' => ['required', 'integer'], + 'temp_max' => ['required', 'integer'] + ]); + + $filament = new Model(); + $filament->name = $this->name; + $filament->description = $this->description; + $filament->color_id = $this->color_id; + $filament->manufacturer_id = $this->manufacturer_id; + $filament->filament_type_id = $this->filament_type_id; + $filament->weight = $this->weight; + $filament->diameter = $this->diameter; + $filament->price = $this->price; + $filament->temp_min = $this->temp_min; + $filament->temp_max = $this->temp_max; + $filament->save(); + + return $this->redirectRoute('filaments.show', $filament->id, navigate: true); + } + + public function cancel(){ + return $this->redirectRoute('filaments.index', navigate: true); } public function render() { - return view('livewire.filament.edit-filament', [ - 'manufacturers' => Manufacturer::all(), - 'colors' => \App\Models\Color::all(), - 'types' => \App\Models\FilamentType::all() + return view('livewire.filament.create', [ ]); } } diff --git a/app/Livewire/Filament/EditFilament.php b/app/Livewire/Filament/EditFilament.php index c4df99c..96ba290 100644 --- a/app/Livewire/Filament/EditFilament.php +++ b/app/Livewire/Filament/EditFilament.php @@ -2,36 +2,79 @@ namespace App\Livewire\Filament; +use Livewire\Attributes\Validate; use Livewire\Component; use App\Models\Filament as Model; -use App\Models\Manufacturer; -use Livewire\WithPagination; use Livewire\Attributes\title; -#[title('Show Filament')] +#[title('Create Filament')] class EditFilament extends Component { - public Model $filament ; - public function back(){ - return redirect()->route('filaments.index'); + public string $name = ''; + public string $description = ''; + public int $color_id = 0; + public int $manufacturer_id = 0; + public int $filament_type_id = 0; + public int $weight = 1000; + public string $diameter = '1.75'; + public float $price = 0; + public int $temp_min = 0; + public int $temp_max = 0; + + #[Validate('required')] + public function save(){ + $this->validate([ + 'name' => ['required', 'string', 'max:255'], + 'description' => ['nullable', 'string', 'max:255'], + 'color_id' => ['required', 'integer'], + 'manufacturer_id' => ['required', 'integer'], + 'filament_type_id' => ['required', 'integer'], + 'weight' => ['required', 'integer'], + 'diameter' => ['required', 'string', 'max:4'], + 'price' => ['required', 'numeric'], + 'temp_min' => ['required', 'integer'], + 'temp_max' => ['required', 'integer'] + ]); + + $this->filament->update([ + 'name' => $this->name, + 'description' => $this->description, + 'color_id' => $this->color_id, + 'manufacturer_id' => $this->manufacturer_id, + 'filament_type_id' => $this->filament_type_id, + 'weight' => $this->weight, + 'diameter' => $this->diameter, + 'price' => $this->price, + 'temp_min' => $this->temp_min, + 'temp_max' => $this->temp_max + ]); + + return $this->redirectRoute('filaments.show', $this->filament->id, navigate: true); } - public function show($id){ - return redirect()->route('filaments.show', $id); + public function cancel(){ + return $this->redirectRoute('filaments.index', navigate: true); } public function mount(Model $filament){ $this->filament = $filament; + $this->name = $filament->name; + $this->description = $filament->description; + $this->color_id = $filament->color_id; + $this->manufacturer_id = $filament->manufacturer_id; + $this->filament_type_id = $filament->filament_type_id; + $this->weight = $filament->weight; + $this->diameter = $filament->diameter; + $this->price = $filament->price; + $this->temp_min = $filament->temp_min; + $this->temp_max = $filament->temp_max; } public function render() { - return view('livewire.filament.edit', [ - 'manufacturers' => Manufacturer::all(), - 'colors' => \App\Models\Color::all(), - 'types' => \App\Models\FilamentType::all() + return view('livewire.filament.create', [ ]); } } diff --git a/app/Livewire/Filament/Filament.php b/app/Livewire/Filament/Filament.php index 5186f7a..ff9468c 100644 --- a/app/Livewire/Filament/Filament.php +++ b/app/Livewire/Filament/Filament.php @@ -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) ]); } } diff --git a/app/Livewire/Filament/ShowFilament.php b/app/Livewire/Filament/ShowFilament.php index 8ae3a23..32dfa56 100644 --- a/app/Livewire/Filament/ShowFilament.php +++ b/app/Livewire/Filament/ShowFilament.php @@ -4,7 +4,6 @@ namespace App\Livewire\Filament; use Livewire\Component; use App\Models\Filament as Model; -use Livewire\WithPagination; use Livewire\Attributes\title; #[title('Show Filament')] @@ -21,13 +20,9 @@ class ShowFilament extends Component return redirect()->route('filaments.edit', $id); } - public function mount(Model $filament){ - $this->filament = $filament; - } - public function render() { - return view('livewire.filament.show-filament', [ + return view('livewire.filament.show', [ ]); } diff --git a/database/migrations/2025_03_10_183058_create_filaments.php b/database/migrations/2025_03_10_183058_create_filaments.php index cb5fa20..20885cc 100644 --- a/database/migrations/2025_03_10_183058_create_filaments.php +++ b/database/migrations/2025_03_10_183058_create_filaments.php @@ -15,20 +15,14 @@ return new class extends Migration $table->id(); $table->string('name'); $table->string('description')->nullable(); - // Foreign keys pointing to existing tables with non-standard names $table->foreignId('color_id')->constrained('colors')->onUpdate('cascade')->onDelete('cascade'); $table->foreignId('manufacturer_id')->constrained('manufacturers')->onUpdate('cascade')->onDelete('cascade'); $table->foreignId('filament_type_id')->constrained('filament_types')->onUpdate('cascade')->onDelete('cascade'); $table->integer('weight'); $table->decimal('diameter', 10, 2); $table->decimal('price', 10, 2)->nullable(); - $table->string('finish')->nullable(); - $table->string('image')->nullable(); - $table->integer('stock')->default(0); $table->integer('temp_min')->nullable(); $table->integer('temp_max')->nullable(); - $table->integer('buildplate_id')->nullable(); - $table->integer('extruder_id')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2025_03_15_185418_create_extruders_table.php b/database/migrations/2025_03_15_185418_create_extruders_table.php index a2ce04e..0ca1875 100644 --- a/database/migrations/2025_03_15_185418_create_extruders_table.php +++ b/database/migrations/2025_03_15_185418_create_extruders_table.php @@ -17,7 +17,7 @@ return new class extends Migration $table->string('description')->nullable(); $table->foreignId('manufacturer_id')->constrained(); $table->string('diameter')->required(); - $table->string('temp_max')->required(); + $table->integer('temp_max')->required(); $table->timestamps(); }); } diff --git a/database/migrations/2025_03_15_185700_create_buildplates_table.php b/database/migrations/2025_03_15_185700_create_buildplates_table.php index e58e012..cb7558d 100644 --- a/database/migrations/2025_03_15_185700_create_buildplates_table.php +++ b/database/migrations/2025_03_15_185700_create_buildplates_table.php @@ -16,7 +16,7 @@ return new class extends Migration $table->string('name'); $table->string('description'); $table->foreignId('manufacturer_id')->constrained('manufacturers'); - $table->string('temp_max'); + $table->integer('temp_max'); $table->timestamps(); }); } diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index 50dbddd..f308320 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -6,28 +6,33 @@