@@ -676,80 +676,26 @@ public static function table(Table $table): Table
676676 SelectFilter::make ('mime_type ' )
677677 ->label (__ ('media::fields.mime_type ' ))
678678 ->options ([
679- 'images ' => __ ('media::fields.images ' ),
680- 'videos ' => __ ('media::fields.videos ' ),
681- 'audios ' => __ ('media::fields.audios ' ),
682- 'documents ' => __ ('media::fields.documents ' ),
679+ 'image ' => __ ('media::fields.images ' ),
680+ 'video ' => __ ('media::fields.videos ' ),
681+ 'audio ' => __ ('media::fields.audios ' ),
682+ 'document ' => __ ('media::fields.documents ' ),
683683 ])
684684 ->query (function (Builder $ query , array $ data ) {
685685 if (!$ data ['value ' ]) {
686686 return $ query ;
687687 }
688688
689- $ mimeTypes = [
690- 'images ' => [
691- 'image/jpeg ' ,
692- 'image/png ' ,
693- 'image/webp ' ,
694- 'image/svg+xml ' ,
695- 'image/gif ' ,
696- 'image/bmp ' ,
697- 'image/tiff ' ,
698- 'image/ico ' ,
699- 'image/heic ' ,
700- 'image/heif ' ,
701- 'image/x-icon ' ,
702- 'image/vnd.microsoft.icon ' ,
703- ],
704- 'videos ' => [
705- 'video/mp4 ' ,
706- 'video/webm ' ,
707- 'video/quicktime ' ,
708- 'video/x-msvideo ' ,
709- 'video/x-matroska ' ,
710- 'video/3gpp ' ,
711- 'video/x-flv ' ,
712- ],
713- 'audios ' => [
714- 'audio/mpeg ' ,
715- 'audio/ogg ' ,
716- 'audio/wav ' ,
717- 'audio/webm ' ,
718- 'audio/aac ' ,
719- 'audio/midi ' ,
720- 'audio/x-midi ' ,
721- 'audio/mp4 ' ,
722- 'audio/flac ' ,
723- ],
724- 'documents ' => [
725- 'application/pdf ' ,
726- 'application/msword ' ,
727- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document ' ,
728- 'application/vnd.ms-excel ' ,
729- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ' ,
730- 'application/vnd.ms-powerpoint ' ,
731- 'application/vnd.openxmlformats-officedocument.presentationml.presentation ' ,
732- 'application/rtf ' ,
733- 'text/plain ' ,
734- 'text/csv ' ,
735- 'text/html ' ,
736- 'text/xml ' ,
737- 'application/json ' ,
738- 'application/x-yaml ' ,
739- 'application/zip ' ,
740- 'application/x-zip-compressed ' ,
741- 'application/x-rar-compressed ' ,
742- 'application/x-7z-compressed ' ,
743- 'application/gzip ' ,
744- 'application/x-tar ' ,
745- ],
746- ];
747-
748- if (isset ($ mimeTypes [$ data ['value ' ]])) {
749- $ query ->whereIn ('mime_type ' , $ mimeTypes [$ data ['value ' ]]);
750- }
751-
752- return $ query ;
689+ return match ($ data ['value ' ]) {
690+ 'image ' => $ query ->where ('mime_type ' , 'like ' , 'image/% ' ),
691+ 'video ' => $ query ->where ('mime_type ' , 'like ' , 'video/% ' ),
692+ 'audio ' => $ query ->where ('mime_type ' , 'like ' , 'audio/% ' ),
693+ 'document ' => $ query ->where (function ($ query ) {
694+ $ query ->where ('mime_type ' , 'like ' , 'application/% ' )
695+ ->orWhere ('mime_type ' , 'like ' , 'text/% ' );
696+ }),
697+ default => $ query ,
698+ };
753699 }),
754700
755701 SelectFilter::make ('uploader ' )
@@ -850,6 +796,22 @@ public static function table(Table $table): Table
850796
851797 return $ query ;
852798 }),
799+ SelectFilter::make ('collection ' )
800+ ->label (__ ('media::fields.collection ' ))
801+ ->options (function () {
802+ return Media::query ()
803+ ->distinct ()
804+ ->pluck ('collection_name ' , 'collection_name ' )
805+ ->filter ()
806+ ->toArray ();
807+ })
808+ ->query (function (Builder $ query , array $ data ) {
809+ if (!$ data ['value ' ]) {
810+ return $ query ;
811+ }
812+
813+ return $ query ->where ('collection_name ' , $ data ['value ' ]);
814+ }),
853815 ])
854816 ->defaultSort ('created_at ' , 'desc ' )
855817 ->paginationPageOptions ([30 , 60 , 90 ])
0 commit comments