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:
@@ -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', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user