feat: Implement withTrashed for polymorphic relationships, enable live updates for order form inputs, and eager load purchase items.

This commit is contained in:
Yoga Pangestu 2025-12-18 10:11:48 +07:00
parent 12053e18f7
commit 9cf985e8f9
6 changed files with 11 additions and 14 deletions

View File

@ -130,7 +130,6 @@ public function columns(): array
if (auth()->user()->can('delete order')) {
$actions .= view('components.actions.table.delete', [
'id' => $row->hash,
'deleteRoute' => route('studio.manage.order.delete', $row->hash),
])->render();
}

View File

@ -67,7 +67,6 @@ public function columns(): array
if (auth()->user()->can('delete purchase')) {
$actions .= view('components.actions.table.delete', [
'id' => $row->hash,
'deleteRoute' => route('studio.manage.purchase.delete', $row->hash),
])->render();
}
@ -81,7 +80,7 @@ public function columns(): array
public function builder(): Builder
{
return Purchase::select('purchases.id', 'outlet_id', 'invoice_number', 'purchase_date', 'total')
->with('outlet')
->with(['outlet', 'items', 'items.purchasable'])
->whereIn('outlet_id', auth()->user()->outlets->pluck('id')->toArray());
}
}

View File

@ -13,7 +13,6 @@
use App\Traits\Utilities\WithUpdatedData;
use Flux\Flux;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Attributes\On;
use Livewire\Attributes\Title;
use Livewire\Component;

View File

@ -48,7 +48,7 @@ public function user(): BelongsTo
public function orderable(): MorphTo
{
return $this->morphTo();
return $this->morphTo()->withTrashed();
}
public function volumes(): HasMany

View File

@ -43,6 +43,6 @@ public function user(): BelongsTo
public function purchasable(): MorphTo
{
return $this->morphTo();
return $this->morphTo()->withTrashed();
}
}

View File

@ -87,7 +87,7 @@
<flux:tab.panel name="new">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<flux:select label="Parfum" variant="listbox" searchable
placeholder="Cari parfum..." wire:model="form.perfume_id">
placeholder="Cari parfum..." wire:model.live="form.perfume_id">
@foreach ($perfumes as $key => $perfume)
<flux:select.option value="{{ $key }}"
wire:key="new-{{ $key }}">
@ -97,7 +97,7 @@
</flux:select>
<flux:select label="Botol" variant="listbox" searchable placeholder="Cari botol..."
wire:model="form.bottle_id">
wire:model.live="form.bottle_id">
@foreach ($bottles as $key => $bottle)
<flux:select.option value="{{ $key }}"
wire:key="new-{{ $key }}">{{ $bottle }}
@ -107,7 +107,7 @@
<div class="col-span-1 md:col-span-2">
@if (!empty($qualities))
<flux:radio.group label="Kualitas" wire:model="form.quality_id"
<flux:radio.group label="Kualitas" wire:model.live="form.quality_id"
variant="buttons" class="w-full *:flex-1">
@foreach ($qualities as $key => $value)
<flux:radio value="{{ $key }}"
@ -130,7 +130,7 @@
<flux:tab.panel name="refill">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<flux:select label="Parfum" variant="listbox" searchable
placeholder="Cari parfum..." wire:model="form.perfume_id">
placeholder="Cari parfum..." wire:model.live="form.perfume_id">
@foreach ($perfumes as $key => $perfume)
<flux:select.option value="{{ $key }}"
wire:key="refill-{{ $key }}">
@ -143,7 +143,7 @@
<flux:label>Ukuran Botol</flux:label>
<flux:input.group>
<flux:input placeholder="Masukkan ukuran botol"
x-mask:dynamic="$money($input, ',')" wire:model="form.bottle_size"
x-mask:dynamic="$money($input, ',')" wire:model.live="form.bottle_size"
autocomplete="off" />
<flux:input.group.suffix>ml</flux:input.group.suffix>
</flux:input.group>
@ -151,7 +151,7 @@
<div class="col-span-1 md:col-span-2">
@if (!empty($qualities))
<flux:radio.group label="Kualitas" wire:model="form.quality_id"
<flux:radio.group label="Kualitas" wire:model.live="form.quality_id"
variant="buttons" class="w-full *:flex-1">
@foreach ($qualities as $key => $value)
<flux:radio value="{{ $key }}"
@ -182,7 +182,7 @@
<flux:card class="space-y-6 p-6">
<flux:select label="Produk" variant="listbox" searchable placeholder="Cari produk..."
wire:model="form.product_id">
wire:model.live="form.product_id">
@foreach ($products as $key => $product)
<flux:select.option value="{{ $key }}"
wire:key="product-{{ $key }}">{{ $product }}
@ -191,7 +191,7 @@
</flux:select>
<flux:input label="Kuantitas" placeholder="Masukkan kuantitas produk"
wire:model="form.quantity_product" autocomplete="off"
wire:model.live="form.quantity_product" autocomplete="off"
x-mask:dynamic="$money($input, ',')" />
<div class="flex justify-end">