【发布时间】:2021-06-23 03:38:12
【问题描述】:
我在 Laravel 中尝试使用来自 Laravel auth 的 RegisterController 中的 create 函数时出现以下错误。我正在尝试使用此函数将数据插入到 2 个表中,插入到用户表和一个与模型角色相关联的名为角色的表中。错误是这样的
Illuminate\Auth\SessionGuard::login(): 参数 #1 ($user) 必须是 类型 Illuminate\Contracts\Auth\Authenticatable,给定 null,调用 D:\xampp\htdocs\SistemaHNF\vendor\laravel\ui\auth-backend\RegistersUsers.php 第 36 行
这是我在创建函数中的代码
protected function create(array $data)
{
$datos= ['nombre' => $data['name'],'apellido' => $data['surname'],'cedula' => $data['cedula'],'email' => $data['email'],
'telefono' =>$data['telefono'],'direccion' =>$data['direccion'],'ciudadResi' =>$data['ciudadResi'],'genero' =>$data['genero'],];
Persona::create([
'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([
'name' => 'clienteUser',
'surname' => $data['surname'],
'email' => $data['email'],
'nick' => $data['nick'],
'password' => Hash::make($data['password']),
'role' => 'cliente'
]);
}
是因为我在函数中缺少返回吗?如果我缺少它,我应该返回什么,因为我将数据插入到 2 个表中。 我是 Laravel 的新手,如果这是一个新手错误,我很抱歉,英语也不是我的主要语言,如果您需要自己更好地解释或任何其他代码,我很乐意提供。
我使用的表格是来自 Register.Blade 的表格
【问题讨论】: