1

Hii i want to store ip addresss in database in laravel 5.1.I have searched in google to store ip address and they suggest me to store ip address like Request::ip(); or other method $request->ip();.when i used this and keep this line as $request->ip(); then it print the ip address.But I have used array $data in auth controller during sign up.

protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'ip' => $data->ip(), ]); } 

the main problem is when i use this line as storing ip like this 'ip' => $data->ip(), it cause error
FatalErrorException in AuthController.php Call to a member function ip() on a non-object.The error is in this line 'ip' => $data->ip(). Can you please help me.

2
  • var_dump your $data Commented Nov 11, 2016 at 5:59
  • Can you explain it more Commented Nov 11, 2016 at 6:48

2 Answers 2

2

You can use request() function which returns the current request instance as:

protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'ip' => request()->ip(), ]); } 
Sign up to request clarification or add additional context in comments.

Comments

0

The reason you are getting the error is that $data is an array, not an object. You cant call functions on an object. Maybe this will work:

'ip' => $data['ip'] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.