1 year ago

#325797

test-img

jaba

how to use links returning paginate to JSON response in AJAX LARAVEL

How can I use or call $data->links() for pagination. In my scenario, I'm using get request using AJAX JavaScript. It return a JSON Response and I want to call $data->links() using JavaScript.

this is my Controller

public function getOrders($store_id)
{
    $data = DB::table('stores')
    ->where('stores.id',$store_id)
    ->paginate(5);

    return response()->json(['data' => $data]);
}

This is my Get Request AJAX

function fetchOrder(){
    $.ajax({
            type: "GET",
            url: "/get-orders/"+store_id,
            dataType: "json",
            success: function (response) {

                if (response.data.data != null) {
                    console.log(response);
                    $('.OrderTbody').html("");
                    $.each(response.data.data, function (key, item) {
                        $('.OrderTbody').append('<tr><td>' + item.store_name + '</td></tr>');

                    });


                }
            }
        });
}

javascript

php

ajax

laravel

laravel-pagination

0 Answers

Your Answer

Accepted video resources