thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.77k stars 2.67k forks source link

Sort images in Media Picker #4948

Open boutzamat opened 4 years ago

boutzamat commented 4 years ago

Version information

Description of problem

I'm not sure if this is already a feature. I searched and searched without any luck. In the Create screen, when using the Media Picker, the sort is by name. It becomes very frustrating when you upload an image to the post, and then have to search for it because it is ordered by name by default.

Proposed solution

Possibility to set the Media Picker sort/order in the field settings where you set the other settings for the media picker.

Alternatives considered

None.

Additional context

Would be good to be able to set the sort on the general Media Picker (the one chosen from the sidebar) as well.

MrCrayon commented 4 years ago

As far as I know is not available but as workaround you can override files method in VoyagerMediaController and reorder them.

This snippet was for something else just to have an idea:

    public function files(Request $request)
    {
        $response = parent::files($request);
​
        if ($response instanceof \Illuminate\Http\JsonResponse) {
            $content = $response->getOriginalContent();
​
            foreach ($content as $key => $item) {
                if ($item['type'] != 'folder') {
                    $content[$key]['path'] .= '?'.$item['last_modified'];
                }
            }
​
            $response->setContent(json_encode($content));
        }
​
        return $response;
    }
emptynick commented 4 years ago

I think this can be easily implemented in JS where we could just manipulate the array which will be stored in the database.