fixed create filament
This commit is contained in:
@@ -60,6 +60,77 @@ class Filament extends Component
|
||||
Flux::modal('createModal')->close();
|
||||
}
|
||||
|
||||
public function edit($filamentid) {
|
||||
@Auth::check();
|
||||
|
||||
$editid = $filamentid;
|
||||
$this->editid = $editid;
|
||||
|
||||
$filament = Model::findOrFail($editid);
|
||||
|
||||
$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->price = $filament->price;
|
||||
$this->stock = $filament->stock;
|
||||
|
||||
Flux::modal('editModal')->show();
|
||||
}
|
||||
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->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->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();
|
||||
@@ -70,7 +141,7 @@ class Filament extends Component
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.filament.filament', [
|
||||
'filaments' => Model::search('name', $this->search)->paginate(10),
|
||||
'filaments' => Model::search('name', $this->search)->paginate(50),
|
||||
'colors' => Color::all(),
|
||||
'manufacturers' => Manufacturer::all(),
|
||||
'types' => Type::all()
|
||||
|
||||
@@ -18,9 +18,9 @@ return new class extends Migration
|
||||
$table->foreignId('color_id')->constrained()->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreignId('manufacturer_id')->constrained()->onUpdate('cascade')->onDelete('cascade');;
|
||||
$table->foreignId('filament_type_id')->constrained()->onUpdate('cascade')->onDelete('cascade');;
|
||||
$table->string('weight')->required();
|
||||
$table->string('diameter')->required();
|
||||
$table->string('price')->nullable();
|
||||
$table->integer('weight')->required();
|
||||
$table->decimal('diameter', 10, 2)->required();
|
||||
$table->decimal('price', 10, 2)->nullable();
|
||||
$table->string('finish')->nullable();
|
||||
$table->string('image')->nullable();
|
||||
$table->integer('stock')->default(0);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
|
||||
|
||||
<div class="container m-auto my-8">
|
||||
<div class="m-auto my-8 mx-12">
|
||||
<x-table>
|
||||
<x-slot name="tableheader">
|
||||
<x-table.header>Name</x-table.header>
|
||||
@@ -43,9 +43,9 @@
|
||||
<x-table.item><p class="p-4 px-3">{{ App\Models\Manufacturer::find($filament->manufacturer_id)->name }}</p></x-table.item>
|
||||
<x-table.item><p class="p-4 px-3">{{ App\Models\FilamentType::find($filament->filament_type_id)->name }}</p></x-table.item>
|
||||
<x-table.item><p class="p-4 px-3">{{ $filament->diameter }} mm</p></x-table.item>
|
||||
<x-table.item><p class="p-4 px-3">{{ $filament->weight }} g/m</p></x-table.item>
|
||||
<x-table.item><p class="p-4 px-3">${{ $filament->price }}</p></x-table.item>
|
||||
<x-table.item><p class="p-4 px-3">${{ $filament->stock }}</p></x-table.item>
|
||||
<x-table.item><p class="p-4 px-3">{{ $filament->weight }} g</p></x-table.item>
|
||||
<x-table.item><p class="p-4 px-3">{{ $filament->price }}€</p></x-table.item>
|
||||
<x-table.item><p class="p-4 px-3">{{ $filament->stock }}</p></x-table.item>
|
||||
<x-table.item>
|
||||
<div class="flex flex-row gap-2 justify-start pr-2">
|
||||
<flux:button wire:click="edit({{ $filament->id }})" variant="ghost" icon="pencil">Edit</flux:button>
|
||||
@@ -63,7 +63,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Create Form -->
|
||||
<flux:modal wire:model.self='createModal' name="createModal" class="md:w-128">
|
||||
<flux:modal wire:model.self='createModal' name="createModal" class="md:w-256">
|
||||
<form wire:submit.prevent="create">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
@@ -72,6 +72,7 @@
|
||||
</div>
|
||||
<flux:input label="Name" wire:model="name" placeholder="Filament Name" required />
|
||||
<flux:textarea label="Description" wire:model="description" placeholder="Description" />
|
||||
<div class="grid grid-cols-2 gap-x-4 gap-y-6">
|
||||
<flux:select wire:model="manufacturer_id" label="Manufacturer">
|
||||
<flux:select.option disabled value="">Choose Manufacturer</flux:select.option>
|
||||
@foreach ($manufacturers as $manufacturer)
|
||||
@@ -93,6 +94,7 @@
|
||||
<flux:input label="Diameter" wire:model="diameter" placeholder="Diameter" required />
|
||||
<flux:input label="Weight" wire:model="weight" placeholder="Weight" required />
|
||||
<flux:input label="Price" wire:model="price" placeholder="Price" required />
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<flux:spacer />
|
||||
<flux:button variant="ghost" wire:click='cancel'>Cancel</flux:button>
|
||||
|
||||
Reference in New Issue
Block a user