I have a user controller with the following validation rules:
public function store(Request $request)
{
...
$this->validate($request, [
'name' => 'required',
'email' => 'email|required|unique:users',
'password' => 'confirmed|max:32|min:8|required',
'roles' => 'exists:roles,id|required',
]);
$user = new User();
$user->fill($request->all());
...
}
My User.php model defines the fillable properties as:
protected $fillable = ['name', 'email'];
To pass the confirmed
validation, I have to send both password
and password_confirmation
fields in the POST request.
During development everything works fine, but in unit tests I'm getting a database error. It tries to insert data into a password_confirmation column. It's like it ignores the $fillable
array.
I know about the "laravel losts event handlers between tests" bug/issue (https://github.com/laravel/framework/issues/1181). So I think that maybe I'm missing to call some model function aside from Model::boot()
(I'm calling User::boot()
in the test's setUp()
function).
Thanks,
Edit
Reading the Model.php source, I've found that someone is calling Model::unguard()
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Model.php#L2180 after the setUp() function and before the test. If I call User::reguard()
at the beggining of the test it passes, but (I don't know why), the unguard() and reguard() functions get called multiple times and the test gets really slow.