Add Filaments module with Seeder, update Calculator UI for filament selection, and upgrade dependencies for Livewire Flux
This commit is contained in:
@@ -8,16 +8,71 @@ use App\Models\Calculationpreset as Model;
|
||||
use Livewire\WithPagination;
|
||||
use Livewire\Attributes\title;
|
||||
|
||||
use App\Models\Filament;
|
||||
use App\Models\FilamentType;
|
||||
use App\Models\Manufacturer;
|
||||
use App\Models\Color;
|
||||
|
||||
#[title('Calculator')]
|
||||
class Calculator extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public Model $calculationpreset ;
|
||||
public string $selection = '1';
|
||||
public float $time = 0;
|
||||
public string $timeunit = 'h';
|
||||
public float $additionalcost = 0;
|
||||
public string $additionalcostunit = 'per Piece';
|
||||
public int $countonplate = 0;
|
||||
public int $selcountonplate = 0;
|
||||
public string $search_type = '';
|
||||
public string $search_manufacturer = '';
|
||||
public string $search_name = '';
|
||||
public string $search_color = '';
|
||||
|
||||
public array $selectedFilaments = []; // [filament_id => amount_g]
|
||||
|
||||
public function toggleFilament($filamentId)
|
||||
{
|
||||
if (isset($this->selectedFilaments[$filamentId])) {
|
||||
unset($this->selectedFilaments[$filamentId]);
|
||||
} else {
|
||||
$this->selectedFilaments[$filamentId] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$filaments = Filament::query()
|
||||
->where(function ($query) {
|
||||
$query->when($this->search_type, function ($query) {
|
||||
$query->whereHas('type', function ($q) {
|
||||
$q->where('name', $this->search_type);
|
||||
});
|
||||
})
|
||||
->when($this->search_manufacturer, function ($query) {
|
||||
$query->whereHas('manufacturer', function ($q) {
|
||||
$q->where('name', 'like', '%' . $this->search_manufacturer . '%');
|
||||
});
|
||||
})
|
||||
->when($this->search_name, function ($query) {
|
||||
$query->where('name', 'like', '%' . $this->search_name . '%');
|
||||
})
|
||||
->when($this->search_color, function ($query) {
|
||||
$query->whereHas('color', function ($q) {
|
||||
$q->where('name', 'like', '%' . $this->search_color . '%');
|
||||
});
|
||||
});
|
||||
})
|
||||
->orWhereIn('id', array_keys($this->selectedFilaments))
|
||||
->with(['type', 'manufacturer', 'color'])
|
||||
->get();
|
||||
|
||||
return view('livewire.calculator', [
|
||||
'presets' => \App\Models\Calculationpreset::all(),
|
||||
'calculationpreset' => \App\Models\Calculationpreset::find($this->selection),
|
||||
'filaments' => $filaments,
|
||||
'filamenttypes' => FilamentType::all(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class Filament extends Model
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'type_id',
|
||||
'filament_type_id',
|
||||
'manufacturer_id',
|
||||
'color_id',
|
||||
'weight',
|
||||
@@ -31,19 +31,19 @@ class Filament extends Model
|
||||
// Filament belongs to a type
|
||||
public function type()
|
||||
{
|
||||
return $this->hasOne(FilamentType::class);
|
||||
return $this->belongsTo(FilamentType::class, 'filament_type_id');
|
||||
}
|
||||
|
||||
// Filament belongs to a manufacturer
|
||||
public function manufacturer()
|
||||
{
|
||||
return $this->hasOne(Manufacturer::class);
|
||||
return $this->belongsTo(Manufacturer::class);
|
||||
}
|
||||
|
||||
// Filament belongs to a color
|
||||
public function color()
|
||||
{
|
||||
return $this->hasOne(Color::class);
|
||||
return $this->belongsTo(Color::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user