Ref : https://github.com/UniSharp/laravel-filemanager/issues/337
Now in vendor/unisharp/laravel-filemanager/public/js/script.js
I have replaced this line:
var sort_type = 'alphabetic';
for this:
var sort_type = 'updated';
To load files order by "time DESC"
you can change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php
you can change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php
public function sortFilesAndDirectories($arr_items, $sort_type)
{
if ($sort_type == 'time') {
$key_to_sort = 'updated';
} elseif ($sort_type == 'alphabetic') {
$key_to_sort = 'name';
} else {
$key_to_sort = 'updated';
}
return strcmp($a->{$key_to_sort}, $b->{$key_to_sort});
});
return $arr_items;
}
with
public function sortFilesAndDirectories($arr_items, $sort_type)
{
if ($sort_type == 'time') {
$key_to_sort = 'updated';
} elseif ($sort_type == 'alphabetic') {
$key_to_sort = 'name';
} else {
$key_to_sort = 'updated';
}
uasort($arr_items, function ($a, $b) use ($key_to_sort) {
if ( $a->$key_to_sort == $b->$key_to_sort )
return 0;
else if ( $a->$key_to_sort > $b->$key_to_sort)
return -1;
else
return 1;
});
return $arr_items;
}
Now in vendor/unisharp/laravel-filemanager/public/js/script.js
I have replaced this line:
var sort_type = 'alphabetic';
for this:
var sort_type = 'updated';
It worked
Thank you for sharing this informative post on Laravel. Looking forward to reading more.
ReplyDeleteBest Laravel Development Services