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 AppModelsProductType;
use LivewireComponent;
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?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…