P
P
Pavel2020-01-01 21:17:50
Laravel
Pavel, 2020-01-01 21:17:50

How to transfer data to the database when sorting through sortable?

Hello everyone, Happy New Year and Merry Christmas!
I'm doing sorting using jquery-ui - sortable
Drag and drop implemented - https://codepen.io/pavel-lipatkin/pen/OJPxBbK
5e0ce22c213bc742008585.jpeg
5e0ce2322301b591029042.jpeg
but how to take the values ​​from the transferred blocks and write them to the database?
Writing to the database directly via AJAX, the data must be transferred to the controller, so that it can be further processed and written to the database

public function sort(){
        $i = 1;
        foreach ($_GET['sortblock'] as $id) {
            //dd($id);
            Model::where('id', $id)->update(['sort'=> $i]);
            $i++;
        }

Threw the code on codepen

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question