Merhaba,
Ürün resimlerini galeriye sıralama vererek kaydetmek istiyorum. Bunun için jquery ui sortable kullanıyorum. Sortable update fonkisyonunda ajax ile sıralamayı galeriye kaydedemedim. Yol gösterir misiniz ... Teşekkürler.
edit.balde.php
<div class="form-group">
<div id="response"></div>
<ul class="sortable">
@foreach($product->images as $image)
<li id='{{ $image->id }}'><img src="{{ $image->featured }}" alt="" class="thumbnail"></li>
@endforeach
</ul>
</div>
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$( ".sortable" ).sortable({
revert: 100,
placeholder: 'placeholder',
update:function(event, ui) {
event.preventDefault();
$.ajax({
type:'POST',
url:'{{ route('productImageSort') }}',
data: $('.sortable').serialize(),
success:function(data){
alert(data.success);
},
error : function() {
alert('error...');
}
});
}
});
</script>
ProductController.php
public function productImageSort(Request $request)
{
dd($request->all());
}
Gallery.php
class Gallery extends Model
{
protected $fillable = ['sort','product_id','file_name','featured'];
public function gallery()
{
return $this->belongsTo('App\Model\Product');
}
}