Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5.4 elequent创建方法生成错误查询_Laravel - Fatal编程技术网

Laravel 5.4 elequent创建方法生成错误查询

Laravel 5.4 elequent创建方法生成错误查询,laravel,Laravel,我试图使用雄辩的create方法在表中插入数据,但我传递的数据并没有进入create方法生成的insert查询。因此,我得到一个默认值错误。 下面是我使用的代码 型号: namespace App; use Illuminate\Database\Eloquent\Model; class PasswordReset extends Model { protected $fillable = ['email', 'token']; } 控制器: $content = ['email

我试图使用雄辩的create方法在表中插入数据,但我传递的数据并没有进入create方法生成的insert查询。因此,我得到一个默认值错误。 下面是我使用的代码

型号:

namespace App;

use Illuminate\Database\Eloquent\Model;

class PasswordReset extends Model
{
    protected $fillable = ['email', 'token'];
}
控制器:

$content = ['email'=>'test@gmail.com', 'token'=>'1234'];
PasswordReset::create($content);
我得到的错误是:

SQLSTATE[HY000]:一般错误:1364字段“电子邮件”没有默认值SQL:insert into password_RESET updated_at,created_at values 2018-09-25 16:16:452018-09-25 16:16:45


为什么上面错误中的查询没有“email”和“token”字段?

试试这个我希望对你有用:

    PasswordReset::create([
'email'=>'test@gmail.com',
'token' => '1234']);

试试这个我希望对你有用:

    PasswordReset::create([
'email'=>'test@gmail.com',
'token' => '1234']);

我认为你应该这样创作

PasswordReset::create([
  'email'=>'test@gmail.com',
  'token' => '1234'
]);

我认为你应该这样创作

PasswordReset::create([
  'email'=>'test@gmail.com',
  'token' => '1234'
]);
试着这样做:

$passwordReset = new PasswordReset();

$passwordReset->email = 'test@gmail.com';

$passwordReset->token = '12345';

$passwordReset->save();
试着这样做:

$passwordReset = new PasswordReset();

$passwordReset->email = 'test@gmail.com';

$passwordReset->token = '12345';

$passwordReset->save();
根据您的评论:

@CBA管理员,谢谢,看了你的评论。我已经检查了我的代码,它有一个_构造方法,但里面没有任何代码,删除它可以解决问题

如果你想在模型上使用_构造,你需要像这样构建它

PasswordReset::create([
  'email'=>'test@gmail.com',
  'token' => '1234'
]);
公共函数uuu constructarray$attributes=[] { 父项::u构造$attributes; //你的代码 } 根据您的评论:

@CBA管理员,谢谢,看了你的评论。我已经检查了我的代码,它有一个_构造方法,但里面没有任何代码,删除它可以解决问题

如果你想在模型上使用_构造,你需要像这样构建它

PasswordReset::create([
  'email'=>'test@gmail.com',
  'token' => '1234'
]);
公共函数uuu constructarray$attributes=[] { 父项::u构造$attributes; //你的代码 }
如果替换受保护的$fillable=[“电子邮件”,“令牌”];使用受保护的$guarded=[id]?您的错误很奇怪,就像您执行了密码重置::create[]。您确定没有重置$content的任何内容吗?@amini.swallow收到相同的错误。这是您的整个模型文件类吗?$content是否如图所示使用?@N69S,没有重置$content的代码如果替换受保护的$filleble=['email','token'],会发生什么情况;使用受保护的$guarded=[id]?您的错误很奇怪,就像您执行了密码重置::create[]。您确定没有重置$content的任何内容吗?@amini.swallow收到相同的错误。这是您的整个模型文件类吗?$content是否如图所示使用?@N69S,没有重置$content的代码。请对模型而不是可填充的$content进行测试:protected$guarded=[]如果是$fillable问题,则错误为MassaSignementException不是SQL错误。请对模型而不是可填充的$protected=[]进行测试如果是$fillable问题,那么错误将是MassAssignementException而不是SQL错误有什么区别?有什么区别?