created Filament View with Livewire

This commit is contained in:
2025-04-22 18:45:56 +02:00
parent 77b1b85f1e
commit cf81ce810b
7 changed files with 434 additions and 19 deletions
+70
View File
@@ -0,0 +1,70 @@
<?php
namespace App\Livewire\Filament;
use Livewire\Component;
use App\Models\Filament as Model;
use App\Models\Color as Color;
use App\Models\FilamentType as Type;
use App\Models\Manufacturer as Manufacturer;
use Livewire\WithPagination;
use Livewire\Attributes\title;
use Livewire\Attributes\Validate;
use Flux\Flux;
use Illuminate\Support\Facades\Auth;
#[title('Filaments')]
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 $price = '0';
public $stock = '0';
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 = 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()
]);
}
}