Skip to content

Instantly share code, notes, and snippets.

@mahammad
Last active March 19, 2020 11:37
Show Gist options
  • Save mahammad/e7a0ed47161c905285d8266c6f9afc29 to your computer and use it in GitHub Desktop.
Save mahammad/e7a0ed47161c905285d8266c6f9afc29 to your computer and use it in GitHub Desktop.

tabloda tr için data-content alanı ekledim

<tr id="item-{{$product->id}}" data-content="{{$product->id}}">
    <td>{{$product->baslik}}</td>
    <td class="sortable">{{$product->altbaslik}}</td>
    <td width="5"><a href="javascript:void(0)"><i class="fa fa-pencil-square"></i></a></td>
    <td width="5"><a href="javascript:void(0)"><i class="fa fa-trash-o"></i></a></td>
</tr>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script type="text/javascript">
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $('#sortable').sortable({
            revert: true,
            handle: ".sortable",
            stop: function (event, ui) {
                let veri = $(this).sortable('toArray', {attribute: 'data-content'});
                $.ajax({
                    type: "POST",
                    url: "{{route('urunler.sortable')}}",
                    data: {
                        veri: veri,
                        urun: 'id-liste',
                    },
                    success: function (msg) {
                        // console.log(msg);
                        if (msg) {
                            console.log(msg);
                        } else {
                            alert("işlem başarısız");
                        }
                    }
                });
            }
        });
        $('#sortable').disableSelection();
    </script>

web.phpbu şekilde Route::post('/sortable', 'SepetController@sortable')->name('urunler.sortable');

Controllerbu şekilde

  public function sortable(Request $request)
    {
        if ($request->ajax()){
            $veri= $request->get('veri');
            $urun = $request->get('urun');
            return response()->json(['success',$urun=>$veri]);
        }else
            return response()->json('error');
    }

Çıktı bu şekilde

id-liste: ["1", "2", "4", "3", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",…]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment