0

I have an ajax call on my view (for filtering results) which calls the action function of vehicleController. However in the response, the pagination creates the next page call like this:

localhost\vehicles\action?page=x

instead of this :

localhost\vehicles\index?page=x

I create pagination with this:

            $data = Vehicle::whereHas('establishment')
                ->Where('transmission', 'like', '%' . $transmission . '%')
                ->where('classification', 'like', '%'.$classification.'%')
                ->whereBetween('daily_price',[$minPrice,$maxPrice])
                ->orderBy('id', 'asc')
                ->paginate(5);

I create the response HTML in the controller and give it back with a response JSON with this:

        $datas = array(
            'table_data'  => $output,
            'total_data'  => $total_row,
            'pagination' => (string) $data->onEachSide(5)->links()
        );
        echo json_encode($datas);

On the source side I have this for the success method:

            success: function (data) {
                $('car_list').html(data.table_data);
                $('pagination').html(data['pagination']);
               //$('#total_records').text(data.total_data);
            }

And I insert the pagination into this:

<pagination> </pagination>
d.gila
  • 38
  • 8

0 Answers0