Sắp xếp theo thứ tự giảm dần theo thời gian với ảnh ,file trên quản lý Laravel File Manager
Thường thì theo mặc định thì Laravel File Manager sẽ sắp xếp file theo thứ tự từ a->z hoặc từ thời gian upload .Giờ sẩy ra việc bạn mới upload ảnh lên mà ảnh đó nằm tít ở trong trang cuối cùng như vậy sẽ rất khó cho việc chọn ảnh show ra ngoài .Dưới đây là cách fix của mình Sort by time DESC
Đầu tiên chúng ta cần sắp xếp lại theo thứ tự desc bằng cách tìm hàm public function sortByColumn trong file vendor\unisharp\laravel-filemanager\src\LfmPath.php
public function sortByColumn($arr_items)
{
$sort_by = $this->helper->input('sort_type');
if (in_array($sort_by, ['name', 'time'])) {
$key_to_sort = $sort_by;
} else {
$key_to_sort = 'name';
}
uasort($arr_items, function ($a, $b) use ($key_to_sort) {
return strcasecmp($a->{$key_to_sort}, $b->{$key_to_sort});
});
return $arr_items;
}
sau đó thay đổi return strcasecmp($a->{$key_to_sort}, $b->{$key_to_sort}); thành return strcasecmp($a->{$key_to_sort}, $b->{$key_to_sort})*-1;
Còn 1 cách khác là thay vì return $arr_items; chúng ta return array_reverse($arr_items);
Vậy là xong 1 phần tiếp theo chúng ta cần thay đổi var sort_type = 'alphabetic'; thành var sort_type = 'time'; trong file public/vendor/laravel-filemanager/js/script.js