I have this div:
@foreach($bids as $b)
<div class="bids notice notice-lg">
<strong>{{$b->user->name}}</strong> siūlo <span style="font-size: 18px" class="label label-success">{{$b->bid}} €</span>
</div>
@endforeach
And this is my AJAX:
$(function(){
$('#placeBid').on('submit',function(e){
$.ajaxSetup({
headers: {
'X-CSRF-Token': $('meta[name="csrf_token"]').attr('content')
}
});
e.preventDefault(e);
if($("#jsBidPrice").val() <= $(".minBid").val()){
$.ajax({
method:"POST",
url: $("#placeBid").attr("action"),
data:$(this).serialize(),
dataType: 'text',
success: function(data){
$('.minBid').val(0);
$("#bidSubmit").attr("disabled", true);
},
error: function(data){
console.log("request failed");
}
})
}
else {
alert('Too low.');
}
});
});
How can I append my div #bids with new submitted data ? This is what I'm trying to right now - I'm trying to create new DIV and place it in foreach value. Like this:
var html = '<strong>{{$b->user->name}}</strong>';
html += 'siūlo <span style="font-size: 18px" class="label label-success">';
html += '54044 €</span>';
$('.bidsA').append(html);
And I place this div over the bids div. So the HTML looks like this:
@foreach($bids as $b)
<div class="bidsA notice notice-lg">
</div>
<div class="bids notice notice-lg">
<strong>{{$b->user->name}}</strong>siūlo <span style="font-size: 18px" class="label label-success">{{$b->bid}} €</span>
</div>
@endforeach
And of course I get undefined variable $b how should I correctly include it from AJAX to HTML ?
EDIT
public function store(BidRequest $request, $id)
{
$product = Product::where('id', $id)->first();
$bid = new Bid([
'product_id' => $product->id,
'bid' => $request->bid,
]);
Auth::user()->bid()->save($bid);
}
}