I have a blade that handles update to a matrix of costs and packages with the value. I’m presenting the information on a table and the lines of the table are components created in a foreach loop. The problem is that livewire doesn’t show the original value of the line, when is put in an input. (I have a discussion opened at Laracast but i have not been able to get an answer)
Here is the blade that calls the nested component:
<button class="btn btn-info" wire:click="openModal">Add New Cost to this Menu</button>
<div>
<table class="tbl">
<thead class="tbl-head">
<tr>
<th>ID</th>
<th>Cost Type</th>
<th>Cost</th>
<th>Mode</th>
<th>Value</th>
<th>Actions</th>
</tr>
</thead>
<tbody class="tbl-body">
@foreach ($costMenuLines as $line)
<livewire:costs.cost-menu-view-lines :costMatrix='$line' :key='$line->id' />
@endforeach
</tbody>
</table>
This is the php for the menu-view-lines :
<?php
namespace App\Http\Livewire\Costs;
use App\Models\CostMatrix;
use Livewire\Component;
class CostMenuViewLines extends Component
{
public $costMatrix;
public $value;
/**
* Undocumented function
*
* @param CostMatrix $costMatrix
* @return void
*/
public function mount(CostMatrix $costMatrix)
{
$this->costMatrix = $costMatrix;
$this->value = $this->costMatrix->value;
}
/**
* Undocumented function
*
* @return void
*/
public function render()
{
return view('livewire.costs.cost-menu-view-lines');
}
public function saveCost()
{
$this->costMatrix->value = $this->value;
$this->costMatrix->save();
}
public function deleteCost()
{
# code...
}
}
Here is the blade for the line:
<div>
<tr>
<td>{{$costMatrix->id}}</td>
<td>{{$costMatrix->cost->costType->name}}</td>
<td>{{$costMatrix->cost->name}}</td>
<td>{{$costMatrix->mode->name}}</td>
<td>
<input wire:model="value" type="text">
</td>
<td>
<button wire:click="saveCost" class="btn btn-info btn-xs">Save</button>
<button wire:click='"deletCost' class="btn btn-danger btn-xs">Delete</button>
</td>
</tr>
</div>
This is the way that shows in the broweser:
I don’t know how to troubleshoot the problem.
In case someone wants to see what had been discussed already at Laracast:
https://laracasts.com/discuss/channels/livewire/input-wiremodel-no-accepting-default
Thanks for the help.