@@ -86,28 +86,61 @@ protected function getFormSchema(): array
8686 ->multiple ()
8787 ->maxItems (10 )
8888 ->searchable ()
89- ->getSearchResultsUsing (function (string $ search ) {
90- $ url = "https://www.speedtest.net/api/js/servers?engine=js&search= {$ search }&https_functional=true&limit=10 " ;
91-
92- $ response = Http::get ($ url );
89+ ->options (function () {
90+ $ response = Http::get (
91+ url: 'https://www.speedtest.net/api/js/servers ' ,
92+ query: [
93+ 'engine ' => 'js ' ,
94+ 'https_functional ' => true ,
95+ 'limit ' => 10 ,
96+ ]
97+ );
98+
99+ if ($ response ->failed ()) {
100+ return [
101+ '' => 'There was an error retrieving Speedtest servers ' ,
102+ ];
103+ }
93104
94- $ options = $ response ->collect ()->map (function ($ item ) {
105+ return $ response ->collect ()->map (function ($ item ) {
95106 return [
96107 'id ' => $ item ['id ' ],
97108 'name ' => $ item ['id ' ].': ' .$ item ['name ' ].' ( ' .$ item ['sponsor ' ].') ' ,
98109 ];
99- });
110+ })->pluck ('name ' , 'id ' );
111+ })
112+ ->getSearchResultsUsing (function (string $ search ) {
113+ $ response = Http::get (
114+ url: 'https://www.speedtest.net/api/js/servers ' ,
115+ query: [
116+ 'engine ' => 'js ' ,
117+ 'search ' => $ search ,
118+ 'https_functional ' => true ,
119+ 'limit ' => 10 ,
120+ ]
121+ );
122+
123+ if ($ response ->failed ()) {
124+ return [
125+ '' => 'There was an error retrieving Speedtest servers ' ,
126+ ];
127+ }
100128
101- if (! $ options ->count () && is_numeric ($ search )) {
102- $ options = collect ([
129+ if (! $ response -> collect () ->count () && is_numeric ($ search )) {
130+ return collect ([
103131 [
104132 'id ' => $ search ,
105133 'name ' => $ search .': No server found, manually add this ID. ' ,
106134 ],
107135 ]);
108136 }
109137
110- return $ options ->pluck ('name ' , 'id ' );
138+ return $ response ->collect ()->map (function ($ item ) {
139+ return [
140+ 'id ' => $ item ['id ' ],
141+ 'name ' => $ item ['id ' ].': ' .$ item ['name ' ].' ( ' .$ item ['sponsor ' ].') ' ,
142+ ];
143+ })->pluck ('name ' , 'id ' );
111144 })
112145 ->columnSpan (2 ),
113146 ])
0 commit comments