phplaravel-5file-management

laravel-filemanager, Sort by time default


I need load files order by "time DESC" when the iframe of laravel-filemanager is called. Is posible? I read the code and see that we cant order by time DESC and the code dont have options to configure a default "sort_type"

https://github.com/UniSharp/laravel-filemanager


Solution

  • i'm change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php and it's worked

       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 == $a->$key_to_sort )
                    return 0;
                else if ( $a->$key_to_sort > $a->$key_to_sort)
                    return -1;
                else
                    return 1;
            });
    
            return $arr_items;
        }