Не особо знаком с jquery, но я сделал так:
jquery:
$( document ).ready(function() {
$('#EditModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)// Button that triggered the modal
var url = button.data('ajax_url');
var id = button.data('id');
var modal = $(this);
var item = $("#item-"+id).data();
modal.find('#form_m').attr('action', url)
modal.find('.modal-body #item-name').val(item.name)
modal.find('.modal-body #item-description').val(item.description)
modal.find('.modal-body #item-price').val(item.price)
modal.find("select[name='item_type_id'] option[value='"+item.item_type_id+ "']").attr("selected","selected");
modal.find("select[name='brand_id'] option[value='"+item.brand_id+ "']").attr("selected","selected");
//$('#ajax_edit_data').on('click', function(){
//
// $.ajax( {
// type: 'POST',
// url: url,
// data: modal.find('#form_m').serialize(),
// success: function(data){
// alert(data)
// }
// });
//
//})
});
$('#DeleteModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var link = button.data('del_url')
var modal = $(this);
modal.find('#form_d').attr('action', link)
});
});
модал:
<div class="modal fade" id="EditModal" tabindex="-1" role="dialog" aria-labelledby="Edit">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Edit item</h4>
</div>
<div class="modal-body">
<form action="replaced_with_js" method="POST" id="form_m">
{!!method_field('PUT')!!}
{!! csrf_field() !!}
<div class="form-group">
<label for="recipient-name" class="control-label">Name:</label>
<input type="text" class="form-control" id="item-name" name="name">
</div>
<div class="form-group">
<label for="message-text" class="control-label">Description:</label>
<textarea class="form-control" id="item-description" rows="10" name="description"></textarea>
</div>
<div class="form-group">
<label for="message-text" class="control-label">Price:</label>
<input type="text" class="form-control" id="item-price" name="price">
</div>
<div class="form-group">
<label class="control-label">Item Type:</label>
<select class="form-control" name="item_type_id">
@foreach($itemTypes as $i)
<option value="{{$i['id']}}">{{$i['name']}}</option>
@endforeach
</select>
</div>
<label class="control-label">Item Type:</label>
<select class="form-control" name="brand_id">
@foreach($brands as $b)
<option value="{{$b['id']}}">{{$b['name']}}</option>
@endforeach
</select>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" form="form_m">Approve</button>
</div>
</div>
</div>
</div>
итем:
<table class="table">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>price</th>
<th>action</th>
</tr>
</thead>
@foreach($items as $i)
<tr id="item-{{$i['id']}}" data-name="{{$i['name']}}"
data-description="{{$i['description']}}"
data-price="{{$i['price']}}"
data-item_type_id="{{$i['item_type_id']}}"
data-brand_id="{{$i['brand_id']}}">
<td>{{$i['id']}}</td>
<td>{{$i['name']}}</td>
<td>{{$i['price']}}</td>
<td>
<button type="button" class="btn btn-primary"
data-toggle="modal" data-target="#EditModal"
data-ajax_url="{{URL::to('/admin')}}/{{$i['id']}}"
data-id="{{$i['id']}}">
Edit
</button>
<button type="button" class="btn btn-danger"
data-toggle="modal" data-target="#DeleteModal"
data-del_url="{{URL::to('/admin')}}/{{$i['id']}}">
Delete
</button>
</td>
</tr>
@endforeach