0
votes

I don't know if it is a bug or just a misusage, so I'm asking here...

on my view :

<div>
    <button wire:click="edit(1)"/>
    @if ($updateMode)
    Editing id {{ $productType->id }} / {{ $productType->name }}
    <input wire:model="productType.id"/> <!-- renders nothing -->
    <input wire:model="productType.name"/> <!-- renders the Product name correctly -->
    @endif
</div>

on my component :


use App\Models\ProductType;
use Livewire\Component;

class ProductTypes extends Component
{
    public ProductType $productType;
    public bool $updateMode;

    public function mount()
    {
        $this->productType = new ProductType();
        $this->updateMode = false;
        $this->productTypes = ProductType::all();
    }

    public function edit($id)
    {
        $this->productType = $this->productTypes->find($id);
        // dd($this->productType->id);
        $this->updateMode = true;
    }

    /** ... */
}

You see there is a dd($this->productType->id) which displays correct information.

But on the view, it always displays the last ProductType it has created.

By using <input wire:model="productType.name"/>, it displays the right info in the input field, but when using {{ $product->name }} is does not. Another note is by using <input wire:model="productType.id"/>it displays empty field, no matter what.

Any idea how to solve this?

1

1 Answers

0
votes

I feel so dumb.

In the view, just replace: {{ $product->name }}

by {{ $this->product->name }}