I have a ul
that consists of li
s which are sortable i.e drag and droppable, I put the ids in an array and try to send to my controller through AJAX but it keeps on saying Internal server error
please what may be the problem
This is my HTML
@if(isset($images_ext)&& !empty($images_ext))
<ul class="reorder1 row">
@foreach ($images_ext as $image)
<li class="img-box" data-src="{{$image->filename}}" id="{{$image->id}}">
<div class="img-w" style="background-image: url('{{$image->filename}}')">
{{-- <a href=""> <img class="mb-2 uploaded-photos " src="{{$image->filename}}" alt=""></a>!--}}
</div>
<span style="color: #333333;position: relative;width: 100%;text-align: justify;
display: inline;">{{$image->description}} <i class="fa fa-upload" style="margin-left: 10px; color:#333333;"></i></span>
</li>
@endforeach
</ul>
@endif
This is my ajax code
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "POST",
url: "{{ action('ImageController@update') }}",
data: {ids: " " + h + ""},
dataType: 'json',
success: function () {
console.log(h);
}
});
This is my Route
Route::post('/settings/orderphotos', 'ImageController@update')->name('settings.updatephotos');
This is my controller
public function update(Request $request){
$data = [];
$count = 1;
// Get images id and generate ids array
$id_array = $request->ids;
$data["success"]= $id_array;
// dd($id_array);
foreach ($id_array as $id) {
$image = Image::findOrFail($id);
$image->update([
'image_order' => $count
]);
$count++;
}
return json_encode('status', 'Image order saved');
}