I'm trying to sort with Jquery UI in Laravel and it's giving me fits.
Here is my controller:
public function postSortSongs(Request $request)
{
$i = 1;
foreach ($request->list_order as $value) {
$i++;
Songs::where('id', '=', $value)->update(['sort_no' => $i]);
}
}
Here's my Javascript:
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script>
var getXsrfToken = function () {
var cookies = document.cookie.split(';');
var token = '';
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].split('=');
if (cookie[0] == 'XSRF-TOKEN') {
token = decodeURIComponent(cookie[1]);
}
}
return token;
};
$.ajaxSetup({
headers: {
'X-XSRF-TOKEN': getXsrfToken()
}
});
$(document).ready(function(){
$('#sortable').sortable({
axis: 'y',
opacity: 0.7,
update: function(event, ui) {
var data = $(this).sortable('serialize');
$.ajax({
url: '{{ route('show_sort_songs_save') }}',
type: 'POST',
data: data
});
}
});
});
</script>
Here is my view:
<ul id="sortable">
@foreach($songs as $song)
<li id="item-{{ $song->id }}">{{ $song->title_of_song->song_title }}</li>
@endforeach
</ul>
And I'm getting an internal 500 error:
send @ jquery.js:26
ajax @ jquery.js:25
update @ main:148
_trigger @ jquery-ui.min.js:6
_trigger @ jquery-ui.min.js:12
(anonymous) @ jquery-ui.min.js:6
(anonymous) @ jquery-ui.min.js:12
_clear @ jquery-ui.min.js:12
(anonymous) @ jquery-ui.min.js:6
_mouseStop @ jquery-ui.min.js:12
(anonymous) @ jquery-ui.min.js:6
_mouseUp @ jquery-ui.min.js:6
(anonymous) @ jquery-ui.min.js:6
n._mouseCapture._mouseDistanceMet._mouseDelayMet._mouseUpDelegate @ jquery-ui.min.js:6
dispatch @ jquery.js:25
q.handle @ jquery.js:24
Can anyone help me? I've looked all over the web and can't find a solution that can help me.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community