i am still new with laravel and livewire. I wanna make sure the user select an option[ADD TRANSACTION] in the dropdown and the value will be appeared in the textbox[TOTAL TO BE PAID] based on the user selection . The value should be amount to be paid based on the id selected by the user.
here is the code that i did some...
Adds.php
use App\Customer;
use App\Order;
class Adds extends Component
{
public $transactDate;
public $orderT;
public $amount;
public $orderss;
public $orderTotal;
public $bankacc;
public $bankname;
public $transactType;
public function render()
{
$this->transactDate = now("Asia/Kuala_Lumpur")->toDateString();
return view('livewire.adds');
}
public function mount()
{
$this->orderT = Order::with('customer')->get();
}
protected $rules = [
'orderss.orderTotal' => 'present',
];
public function display($id)
{
$this->orderss = $this->orderT->find($id);
}
}
adds.blade
<div class="col-sm-12 col-md-6" >
<div class="card">
<div class="card-body">
<h3 class="card-title">Add Transaction</h3>
<form action="" method="POST">
@csrf
<label class="form-control-label" >Transaction Date</label>
<input type="text" class="form-control" name="unit" wire:model="transactDate" value="{{ $transactDate }}" readonly >
</br>
<label class="form-control-label" >Add Transaction</label>
<div class="form-group mb-4">
<select class="form-control mr-sm-2" wire:model="orderT">
<option value='' selected >Select order</option>
@foreach ($orderT as $os)
@if(($os->orderStatus === 'Completed') or ($os->orderStatus === 'In process[PAID]'))
<option value="{{$os->id}}" > {{$os->id}}-{{$os->customer->custName}}</option>
@endif
@endforeach
</select>
</div>
<label class="form-control-label" >Total to be paid RM</label>
<input type="text" class="form-control" name="amount" value=""wire:model="orderss.orderTotal" readonly >
</br>
<label class="form-control-label" >Choose Type of Payment</label>
<div class="form-group mb-4">
<select class="form-control mr-sm-2" wire:model="transactType">
<option disabled selected>Select payment</option>
<option value="1" >Cash</option>
<option value="2" >Bank Transfer</option>
</select>
</div>
<label class="form-control-label" >Bank Account Number</label>
<input type="text" class="form-control" name="unit" value="" placeholder="XXXXXXX" wire:model="bankacc" >
</br>
<label class="form-control-label" >Bank Account Name</label>
<input type="text" class="form-control" name="unit" value="" placeholder="eg: Bank Islam" wire:model="bankname" >
</br>
<div class="form-actions">
<div class="text-right">
<button type="submit" class="btn btn-info">Submit</button>
<button type="reset" class="btn btn-dark">Reset</button>
</div>
</div>
</form>
</div>
</div>
do view the image to visualize
hope anyone can help me out! i have 2 use case left to finish for my final year project
look at this line
<select class="form-control mr-sm-2" wire:model="orderT">
// instead
<select class="form-control mr-sm-2" wire:model="selectedOrder">
<option value=''>Select order</option>
@foreach ($orderT as $os)
@if(($os->orderStatus === 'Completed') or ($os->orderStatus === 'In process[PAID]'))
<option value="{{$os->id}}" > {{$os->id}}-{{$os->customer->custName}}</option>
@endif
@endforeach
</select>
you're binding to the same property here to the same you retrieve the options. I suggest you, create a new property, eg. selectedOrder
public $selectedOrder = "";
public $amount;
public function updatedSelectedOrder($value)
{
$this->amount = Order::where('id', $value)->first()->orderTotal;
}
then you can bind the value to the element
<label class="form-control-label" >Total to be paid RM</label>
<input type="text" class="form-control" name="amount" value=""wire:model="amount" readonly >
</br>