@@ -12,16 +12,16 @@ public static function search_community_stores($search, $letter): array
1212 {
1313
1414 // validate that search is not empty and only english alphabetic characters
15- if (( blank ($ search ) || ! preg_match ( ' /^[a-zA-Z]+$/ ' , $ search )) && blank ( $ letter )) return [];
15+ if (blank ($ search ) && ( blank ( $ letter ) || $ letter == " -1 " )) return [];
1616
17- $ to_search = strtolower ($ search ?? $ letter );
17+ if (strlen ($ search ) > 1 )
18+ $ letter = substr ($ search , 0 , 1 );
1819
19- if ($ to_search == '-1 ' ) return [];
2020
2121 // check the github repo for the first letter of the search
2222 $ github_link = config ('settings.github_community_store_repo ' );
2323
24- $ stores_available = Http::get ($ github_link .$ to_search )
24+ $ stores_available = Http::get ($ github_link . strtolower ( $ letter ) )
2525 ->json ();
2626
2727 if (array_key_exists ('message ' , $ stores_available )) {
@@ -34,6 +34,11 @@ public static function search_community_stores($search, $letter): array
3434 return [];
3535 }
3636
37+ // filter store by search
38+ if (strlen ($ search ) > 1 ) {
39+ $ stores_available = array_filter ($ stores_available , fn ($ store ) => Str::contains ($ store ['name ' ], $ search , true ));
40+ }
41+
3742 $ formatted_stores = array_map (fn ($ store ) => [
3843 'name ' => $ store ['name ' ],
3944 'image ' => config ('settings.github_community_store_gist_base ' ).$ store ['path ' ].'/logo.png ' ,
0 commit comments