Torann / laravel-geoip

Determine the geographical location of website visitors based on their IP addresses.
http://lyften.com/projects/laravel-geoip
BSD 2-Clause "Simplified" License
2.11k stars 372 forks source link

Works fine in webpage but not works in api response #208

Closed vadimwe closed 2 years ago

vadimwe commented 3 years ago

Works fine in webpage but not works in api response. Is it possible to use it in api with api middleware?

vadimwe commented 2 years ago

any ideas?

vadimwe commented 2 years ago

No errors in logs or in runtime. Just empty object in both cases.

return response()->json([ 'status' => 1, 'geoip' => geoip()->getLocation(), '_geoip' => geoip() ]);

I`m confused. Same code works fine with blade response

vadimwe commented 2 years ago

@Cod3rMax big thanks for your help.

'geoip' => geoip()->getLocation()->toArray(), works excellent.

response()->json() should convert object properties to array automatically but seems not in this case.

vadimwe commented 2 years ago

geoip()->getLocation()->toArray() works perfect.

Have a great day too!