diff --git a/app/Livewire/Filament/Filament.php b/app/Livewire/Filament/Filament.php new file mode 100644 index 0000000..50758a9 --- /dev/null +++ b/app/Livewire/Filament/Filament.php @@ -0,0 +1,70 @@ +validate(); + + $filament = new Model(); + $filament->name = $this->name; + $filament->description = $this->description; + $filament->diameter = $this->diameter; + $filament->color_id = Color::Find($this->color_id); + $filament->filament_type_id = Type::Find($this->type_id); + $filament->manufacturer_id = Manufacturer::Find($this->manufacturer_id); + $filament->weight = $this->weight; + $filament->price = $this->price; + $filament->stock = $this->stock; + $filament->save(); + + // Clear the form + $this->resetInputFields(); + + // Close the modal + Flux::modal('createModal')->close(); + } + public function render() + { + return view('livewire.filament.filament', [ + 'filaments' => Model::search('name', $this->search)->paginate(10), + 'colors' => Color::all(), + 'manufacturers' => Manufacturer::all(), + 'types' => Type::all() + ]); + } +} diff --git a/app/Livewire/Filament/Manufacturer.php b/app/Livewire/Filament/Manufacturer.php index 0297681..c948e3d 100644 --- a/app/Livewire/Filament/Manufacturer.php +++ b/app/Livewire/Filament/Manufacturer.php @@ -3,11 +3,110 @@ namespace App\Livewire\Filament; use Livewire\Component; +use Livewire\WithPagination; +use App\Models\Manufacturer as Model; +use Livewire\Attributes\title; +use Livewire\Attributes\Validate; +use Flux\Flux; +use Illuminate\Support\Facades\Auth; + +#[title('Manufacturer List')] +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 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 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 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']); + } -class Manufacturer extends Component -{ public function render() { - return view('livewire.filament.manufacturer'); + return view('livewire.filament.manufacturer', [ + 'manufacturers' => Model::search('name', $this->search)->paginate(10) + ]); } } diff --git a/app/Models/Filament.php b/app/Models/Filament.php index caf5dca..91cf94e 100644 --- a/app/Models/Filament.php +++ b/app/Models/Filament.php @@ -31,19 +31,19 @@ class Filament extends Model // Filament belongs to a type public function type() { - return $this->belongsTo(FilamentType::class); + return $this->hasOne(FilamentType::class); } // Filament belongs to a manufacturer public function manufacturer() { - return $this->belongsTo(Manufacturer::class); + return $this->hasOne(Manufacturer::class); } // Filament belongs to a color public function color() { - return $this->belongsTo(Color::class); + return $this->hasOne(Color::class); } } diff --git a/database/migrations/2025_03_10_183058_create_filaments.php b/database/migrations/2025_03_10_183058_create_filaments.php index 1f7fdc5..d530693 100644 --- a/database/migrations/2025_03_10_183058_create_filaments.php +++ b/database/migrations/2025_03_10_183058_create_filaments.php @@ -15,9 +15,9 @@ return new class extends Migration $table->id(); $table->string('name')->required(); $table->string('description')->nullable(); - $table->foreignId('color_id')->constrained(); - $table->foreignId('manufacturer_id')->constrained(); - $table->foreignId('filament_type_id')->constrained(); + $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(); diff --git a/resources/views/livewire/filament/filament.blade.php b/resources/views/livewire/filament/filament.blade.php new file mode 100644 index 0000000..d3bc2fd --- /dev/null +++ b/resources/views/livewire/filament/filament.blade.php @@ -0,0 +1,136 @@ +
+ + {{ __('Filaments') }} + + + + + + + + Create Filament + + + + + + + +
+ + + Name + Description + Color + Manufacturer + Material + Diameter + Weight + Price + Rolls + + + + @foreach ($filaments as $filament) + +

{{ $filament->name }}

+

{{ $filament->description }}

+

+ +
+ Edit + Delete +
+
+ + @endforeach + + + {{ $filaments->links() }} + +
+ +
+ + + +
+
+
+ Create filament + Create a new filament. +
+ + + + @foreach ($manufacturers as $manufacturer) + + @endforeach + + + @foreach ($types as $type) + + @endforeach + + + @foreach ($colors as $color) + + @endforeach + + + + +
+ + Cancel + Create +
+
+
+
+ + + @empty($filament) + @else + +
+
+
+ Edit manufacturer + Edit an existing manufacturer. +
+ + +
+ + Cancel + Save +
+
+
+
+ @endempty + + + +
+
+
+ Delete filament? + +

You're about to delete this filament.

+

This action cannot be reversed.

+
+
+ + +
+ + Cancel + Delete filament +
+
+
+
+ +
\ No newline at end of file diff --git a/resources/views/livewire/filament/manufacturer.blade.php b/resources/views/livewire/filament/manufacturer.blade.php index 15e5660..4cd0f83 100644 --- a/resources/views/livewire/filament/manufacturer.blade.php +++ b/resources/views/livewire/filament/manufacturer.blade.php @@ -1,3 +1,116 @@ -
- {{-- The whole world belongs to you. --}} -
+
+ + {{ __('Manufacturers') }} + + + + + + + + Create Manufacturer + + + + + + +
+ + + Name + Description + Website + Rolls + + + + @foreach ($manufacturers as $manufacturer) + +

{{ $manufacturer->name }}

+

{{ $manufacturer->description }}

+

{{ $manufacturer->website }}

+

+ +
+ Edit + Delete +
+
+ + @endforeach + + + {{ $manufacturers->links() }} + +
+ +
+ + + +
+
+
+ Create manufacturer + Create a new manufacturer. +
+ + + +
+ + Cancel + Create +
+
+
+
+ + + @empty($manufacturer) + @else + +
+
+
+ Edit manufacturer + Edit an existing manufacturer. +
+ + + +
+ + Cancel + Save +
+
+
+
+ @endempty + + + +
+
+
+ Delete manufacturer? + +

You're about to delete this manufacturer.

+

This action cannot be reversed.

+
+
+ + + +
+ + Cancel + Delete type +
+
+
+
+ +
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index afdf071..63fce96 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,14 +1,12 @@ name('types.index'); // Filaments - Route::resource('filaments', FilamentController::class); + Route::get('filaments', Filament::class)->name('filaments.index'); // Manufacturers - Route::resource('manufacturers', ManufacturerController::class); - Route::get('refresh', [ManufacturerController::class, 'refresh'])->name('refresh'); + Route::get('manufacturers', Manufacturer::class)->name('manufacturers.index'); });