Support the ongoing development of Laravel.io →
Requests Database Packages
Last updated 2 years ago.
0

Add a new field to the table called "sort_order"

Create a way for users to change the sort order. You can give them a list of items to sort and include a text box that shows the current sort order, allow them to change all the values to order them the way they want then save the values to the database.

Any places that list these items can ->orderBy('sort_order')

Another option is to list all the items they want to sort and provide "Up and down" links... clicking the up link swaps the sort_order value with the item above it... clicking the down link swaps the wort_order item below it.

Last updated 2 years ago.
0

Hi IanSirkit,

I like both options you proposed and perhaps I should use both. Though I like the second option you proposed better. My question: how to get the row "above" it or row "below it"?

Thanks in advance!

Last updated 2 years ago.
0

What I do is this

// get object one sort order smaller 
row_above = "select * from table where sort_order < $sort_order_of_object_we_are_moving_up order by sort_order desc limit 1


// get object one sort order larger
row_below = "select * from table where sort_order > $sort_order_of_object_we_are_moving_down order by sort_order asc limit 1
Last updated 2 years ago.
0

IanSirkit said:

What I do is this

// get object one sort order smaller 
row_above = "select * from table where sort_order < $sort_order_of_object_we_are_moving_up order by sort_order desc limit 1


// get object one sort order larger
row_below = "select * from table where sort_order > $sort_order_of_object_we_are_moving_down order by sort_order asc limit 1

Thanks - I'm going to give this a shot.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

hammer078 hammer078 Joined 18 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.