Files

81 lines
2.6 KiB
PHP

<?php
namespace App\Livewire\Filament;
use Livewire\Attributes\Validate;
use Livewire\Component;
use App\Models\Filament as Model;
use Livewire\Attributes\title;
#[title('Create Filament')]
class EditFilament extends Component
{
public Model $filament ;
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 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.create', [
]);
}
}