Custom Bulk Import
When I am importing a large amount of data through an Excel sheet, the original sequence is changed while displaying on the index page whereas in the database it is stored in the same sequence that was uploaded in the Excel sheet. What should I do to store in the same sequence as the Excel sheet in the index page as well?
4 Replies
Did you meant in list it should display from "cat 1, cat 2, cat 3" and so on...?
If yes, then you need to put
->defaultSort('id', 'asc')
in table, by default it sorted using created_at, asc
iirc
Correction by default it sorted using 'id', 'asc'
but in your case maybe you have different sort optionHi, I was using ->latest() before
So I added latest()->orderBy('id', 'desc') and it is working fine now.
Tip:
latest()
is same as orderBy('created_at', 'desc')
in your case you can remove completely cause it doesn't make sense Or you can just do latest('id')
When I wasn't mentioning latest(), the recently created data wasn't displayed on the top, so used that. Thanks though!