I Have a List of projects and three type of payments for any project I Want to give all type of payments and send payment id to ajax But I give just id=1 for all request my Code is here:
@foreach($project->payments as $payment)
@if($payment->type==1)
@if(empty($payment->code))
<input type="hidden"id="payment_id"value="{{$payment->id}}">
<input type="text" class="form-control" id="paymentCode" name="paymentC">
{{csrf_field()}}
<button id="AddCode" type=submit class="btn btn-info generate-label AddCode">enter</button>
@else
{{$payment->code}}
@endif
@elseif($payment->type==2)
@if(empty($payment->code))
<input type="hidden" id="payment_id" value="{{$payment->id}}">
<input type="text" class="form-control" name="paymentC" id="paymentCode">
{{csrf_field()}}
<button id="AddCode" type="submit" class="btn btn-info generate-label AddCode">enter</button>
@else
{{$payment->code}}
@endif
@endif
@endforeach
Javascript Code:
$('.AddCode').click (function (event) {
var payment_id = $('#payment_id').val();
var paymentCode = $('#paymentCode').val();
console.log(payment_id);
});
How I Can fix my problem that When click in button of payment print this id?