Support the ongoing development of Laravel.io →
Requests Database Laravel.io
Last updated 2 years ago.
0

If you are not passing the request data with the $data array, i.e. if you are performing the IP request in Registrar.php, then you may have to add the following line

use Illuminate\Http\Request

or

use Request
Last updated 9 years ago.
0

I use it my code:

<?php namespace App\Services;

use App\User;
use Illuminate\Http\Request;
use Validator;
use Illuminate\Contracts\Auth\Registrar as RegistrarContract;

class Registrar implements RegistrarContract {

	/**
	 * Get a validator for an incoming registration request.
	 *
	 * @param  array  $data
	 * @return \Illuminate\Contracts\Validation\Validator
	 */
	public function validator(array $data)
	{
		return Validator::make($data, [
			'name' => 'required|max:255',
			'email' => 'required|email|max:255|unique:users',
			'password' => 'required|confirmed|min:6',
		]);
	}

	/**
	 * Create a new user instance after a valid registration.
	 *
	 * @param  array  $data
	 * @return User
	 */
	public function create(array $data)
	{
		return User::create([
                       'name' => $data['name'],
			'ip' => Request::ip(),
			'email' => $data['email'],
			'password' => bcrypt($data['password']),
		]);
	}

}

but it do not work and error is:

Non-static method Illuminate\Http\Request::ip() should not be called statically, assuming $this from incompatible context
Last updated 9 years ago.
0
Solution

I don't think you can call request statically and expect data from the current request. You need a copy of the request object.

Have you tried

public function create(array $data, Request $request)

   'ip' => $request->ip, 
0

@snapey thank you it work but otherwise you say i must change create method in compiled.php really thank you ;)

Last updated 9 years ago.
0

@snapey

Isn't that the same as using

use Request;

as I suggested above? You simply inject the Request class directly into the function...

0

Sign in to participate in this thread!

Eventy

Your banner here too?

k00r0sh k00r0sh Joined 14 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.