33namespace App \Http \Controllers \API ;
44
55use Illuminate \Http \Request ;
6- use App \ Http \ Controllers \Controller ;
6+ use Illuminate \ Routing \Controller ;
77use App \Models \Gateway ;
88use Validator ;
99
@@ -26,27 +26,27 @@ public function ping(Request $request)
2626 'sys_load ' => 'required|numeric ' ,
2727 'wifidog_uptime ' => 'required|integer ' ,
2828 ]);
29- $ r = 'Error: params wrong ' ;
29+ $ responseTxt = 'Error: params wrong ' ;
3030 if ($ validator ->fails ()) {
31- return response ()->txt ($ r , 400 );
31+ return response ()->txt ($ responseTxt , 400 );
3232 }
3333 $ input = $ validator ->getData ();
3434 $ input ['id ' ] = $ input ['gw_id ' ];
3535 unset($ input ['gw_id ' ]);
36- $ status_code = 200 ;
36+ $ statusCode = 200 ;
3737 if (config ('wifidog.allow_unknown_gateway ' )) {
3838 Gateway::updateOrCreate (['id ' => $ input ['id ' ]], $ input );
39- $ r = 'Pong ' ;
40- } else {
41- $ gw = Gateway::find ($ input ['id ' ]);
42- if (!empty ($ gw )) {
43- $ gw ->update ($ input );
44- $ r = 'Pong ' ;
45- } else {
46- $ r = 'Error: not allow unknown gateway ' ;
47- $ status_code = 400 ;
48- }
39+ $ responseTxt = 'Pong ' ;
40+ return response ()->txt ($ responseTxt , $ statusCode );
4941 }
50- return response ()->txt ($ r , $ status_code );
42+ $ gateway = Gateway::find ($ input ['id ' ]);
43+ if (!empty ($ gateway )) {
44+ $ gateway ->update ($ input );
45+ $ responseTxt = 'Pong ' ;
46+ return response ()->txt ($ responseTxt , $ statusCode );
47+ }
48+ $ responseTxt = 'Error: not allow unknown gateway ' ;
49+ $ statusCode = 400 ;
50+ return response ()->txt ($ responseTxt , $ statusCode );
5151 }
5252}
0 commit comments