Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danmatthews's avatar

A nice RESTful way to bulk update 'order' on a pivot table , thoughts?

I have a Quiz model that has a belongsToMany relationship with another model called Question via a pivot table. Also stored on that pivot table is an 'order' column - which basically informs a controller/view which order to render on a page.

It's something i want my users to be able to update via the API so they can re-arrange the fields (and something i will be building a drag/drop interface for in my own front-end app).

I could use the update method on my resourceful controller to update each question with the new order - but that could result in 20-30 requests on a larger Quiz.

Does anyone have an opinion on the best way to perhaps bulk update this information in one request? i want to try and stay as RESTful as can be.

I know it's not a life-changing decision, but i'd like to know if there's a 'done' way of doing things like this.

0 likes
3 replies
rockhopper72's avatar

Maybe you could store the order column as an array on the Quiz model instead of the Question model?

danmatthews's avatar

@rockhopper72 hmm, never thought of that, it needs to be a column on something though as i need to be able to use orderBy to return the Questions in the correct order.

I'm just jumping through google results now to see if REST has a standard way of pushing bulk updates.

andcl85's avatar

Did you get a solution for this? Thanks.

Please or to participate in this conversation.