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
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
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,
@snapey thank you it work but otherwise you say i must change create method in compiled.php really thank you ;)
Isn't that the same as using
use Request;
as I suggested above? You simply inject the Request class directly into the function...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.