laravel sort collection of filenames

Viewed 34

I having trouble reading some files alphabetically as shown in the picture. Is required that they keep the order after reading them because they will generate respective records in a table later. I tried collect and sort options but unlucky. In the pc filesystem they appear in the correct order

I get an array of files with this code and then print the array with dd(), so ultimately I want to sort those filenames alphabetically.

$files = ((Storage::disk('public')->files("uploads"))); 

dd($files);

I tried sort collection method, also convert into array and use asort() but no luck

thanks, any help is appreciated

image of dd()

I think I got the answer with this: (I'm happy)

$files = ((Storage::disk('public')->files("uploads")));
sort($files, SORT_NATURAL);

sorted

1 Answers

you can use sort method eg:

$collection->sortKeysDesc();
Related