I am putting together an application, where an employee is registered, and this employee belongs to a company, which comes from the users table.
When I do the registration process, the following error message appears:
"SQLSTATE[HY000]: General error: 1364 Field 'users_id' doesn't have a default value (SQL: insert into 'funcionarios' ('name', 'email', 'password', 'perfil_id', 'updated_at', 'created_at') values (Gustavo, [email protected], $2y$10$nRqXsSPGybF1rMFQRsMwLOmiofkGp7voaJRnOwUEewMYXR1oyBDya, 3, 2018-07-03 01:36:22, 2018-07-03 01:36:22)) ◀"
However, by parsing the code, and debugging it, the variable that passes the id to the officials table is populated with the id of the logged-in user. The method is as follows:
public function cadastraFuncionario(Request $request){
$this->validate($request, [
'name' => ['required', 'max:255'],
'email' => ['required', 'max:255', 'email', 'unique:funcionarios'],
'password' => ['required', 'min:6', 'max:20']
]);
$id_empresa = Auth::user()->id;
$credentials = array_merge($request->all(), [
'password' => bcrypt($request->input('password')),
'perfil_id' => 3,
'users_id' => $id_empresa,
]);
var_dump($credentials);
Funcionario::create($credentials);
return redirect('/dashboard');
}
When I give a var_dump in the variable, I have the following return:
C:\Users\Gustavo\project-manager\app\Http\Controllers\FuncionarioController.php:34:
array (size=6)
'_token' => string 'xAhxSeW6hQVb1k5PFYhgTvd8Y7rWkmn38IXt08ND' (length=40)
'name' => string 'Gustavo' (length=7)
'email' => string '[email protected]' (length=18)
'password' => string '$2y$10$hS816jGMo2BHpgL8/7d/buWmrwnKKjjiW.dIxYwnEFaMMwyAgZClS' (length=60)
'perfil_id' => int 3
'users_id' => int 1
I can not identify the error. I have already tried to set the direct value in the body of the method, as I did with profile_id, but it does not work.