Level 102
If the javascript is in a blade file, just use blade syntax
var price={{$room->price}};// i dont know how to assign ($price Value)
var noDate={{$diffDate}; // i dont know how to assign ($diffDate value)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
controller pass variable to blade and how can pass to ajax variable?
controller
public function create(Request $request, Room $room)
{
$resultCount=2;
$diffDate= $check_out->diffInDays($check_in);
return view('International', compact('room','diffDate',' resultCount'));
}
blade
<label > Select Qty:</label><br>
<div class="form-check">
<select id="qty" name="qty">
<option value="">--- Select Qty ---</option>
@for ($i = 1; $i < $resultCount; $i++)
<option value="{{$i}}">{{$i}}</option>
@endfor
</select>
</div>
<h4 class="d-flex justify-content-between align-items-center mb-3">
<span class="text-muted">Reservation Info</span>
</h4>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<h6 class="my-0">No Date</h6>
</div>
<span class="text-muted">{{ $diffDate }}</span>
</li>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<h6 class="my-0">Quantity</h6>
</div>
<!-- {{ $room->quantity }} -->
<span id="roomQty" class="text-muted"></span>
</li>
//ajax
$('#qty').change(function(){
var price=room->price;// i dont know how to assign ($price Value)
var noDate=diffDate; // i dont know how to assign ($diffDate value)
var qty = $("#qty").val();
$.ajax(
{
url: "{{route('ajax.international.qtyChange')}}?qty="+qty,
type: 'GET',
success: function (res){
if(res){
$("#roomQty").html(res.qty);
}else{
$("#roomQty").empty();
}
}
});// ajax
});
any help please
Please or to participate in this conversation.