php - Variable undifined when trying to insert values from 1 form into 2 tables with RegisterControlller in Laravel 8Get the solution ↓↓↓
I'm trying to use the registerController to insert data into 2 tables of SQL, the Users table of Laravel and one table called personas that is associated to the Persona Model.
$datos= ['nombre' => $data['name'],'apellido' => $data['surname'],'cedula' => $data['cedula'],'email' => $datos['email'], 'telefono' =>$datos['telefono'],'direccion' =>$datos['direccion'],'ciudadResi' =>$datos['ciudadResi'],'genero' =>$datos['genero'],]; Persona::create($datos)([ 'nombre' => $datos['nombre'], 'apellido' => $datos['apellido'], 'cedula' => $datos['cedula'], 'email' => $datos['email'], 'telefono' =>$datos['telefono'], 'direccion' =>$datos['direccion'], 'ciudadResi' =>$datos['ciudadResi'], 'fechaNacimiento' =>'1998-03-05', 'genero' =>$datos['genero'], 'estado'=> '1', 'idTipoPersona'=>'2' ]); User::create($data)([ 'name' => 'clienteUser', 'surname' => $data['surname'], 'email' => $data['email'], 'nick' => $data['nick'], 'password' => Hash::make($data['password']), 'role' => 'cliente' ]);
That is the code in the RegisterController that is generated by auth of Laravel, what I'm trying to do is get the $data from the form in register.blade because I don't need the updated_at and created_at that $data have I want to store the values I want to insert in the persona table in the $datos array, insert them into the table and insert the values I need for User form Data.
When I try to do that it says that $datos is undefined. What should I need to solve the problem? English is not my main language so I would appreciate if explanations are easy.
inside $datos array, there is $datos present.. i think thats where the error comes from.. i think it should be $data instead of $datos inside $datos array
People are also looking for solutions of the problem: cannot access offset of type string on string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.