hcastillo's avatar

Fetch remaining data from paginated respond in Vue SPA

how i could make to bring all data in once on pagination data response without create another end-point? Example

// Laravel method
public function getCars()
{
return Car::paginated();
}

// Vue SPA
    // Using paginated data | work perfect
   const getCars = async (page = 1) => {
        const { data } = await httpClient.get("cars?page=" + page)
        return data
    }

     //Lets say that i have 60 records, but i want to call the same end-point but bring all data in once
    
0 likes
4 replies
jlrdw's avatar

If I understand correctly, it would be an if statement to figure out if paginating or not. And from back end return whatever results are needed.

Similar in front end show or don't show pagination.

1 like
recepgums's avatar
public function getCars()
{   

if	(request()->has('all') && request()->get('all')){
	return Car::all();
}

return Car::paginated();
}

Vue SPA

await httpClient.get("cars?all=1")

This is not the best practice for sure but I think this would give you the idea

1 like
martinbean's avatar

@jlrdw You can’t make a server-side endpoint magically return all records. Instead, do a for loop or something in your JavaScript code that hits the endpoint as many times as it needs to, incrementing the page number each time.

1 like
jlrdw's avatar

@martinbean I was going by this:

//Lets say that i have 60 records, but i want to call the same end-point but bring all data in once

It sounded like he doesn't want to paginate here, rather show all 60. That's why I said If I understand correctly.

1 like

Please or to participate in this conversation.