I have this code:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'ip' => $_SERVER['REMOTE_ADDR'],
'country' => 'http://ip-api.com/json/'.$_SERVER['REMOTE_ADDR'],
'password' => bcrypt($data['password']),
'secret_question' => $data['secret_question'],
'question_answer' => $data['question_answer'],
]);
}
}
This is register function in laravel controller called AuthController.php
This line 'ip' => $_SERVER['REMOTE_ADDR'],
works fine, I'm gettig user's IP.
This http://ip-api.com/json/YOURipADDRESS API which detects not only location but also it detects some more stuff based on IP address. I only need to get countryCode
from that API and store it to DB. How to do it correctly in this file ?
EDIT
This is my function right now but DB country is empty.
protected function create(array $data)
{
$user_details = json_decode(file_get_contents('http://ip-api.com/json/'.$_SERVER['REMOTE_ADDR']));
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'ip' => $_SERVER['REMOTE_ADDR'],
'country' => $user_details->country,
'password' => bcrypt($data['password']),
'secret_question' => $data['secret_question'],
'question_answer' => $data['question_answer'],
]);
}