Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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
Php 无法使用laravel在数据库中插入所有内容_Php_Laravel_Eloquent_Laravel 5 - Fatal编程技术网

Php 无法使用laravel在数据库中插入所有内容

Php 无法使用laravel在数据库中插入所有内容,php,laravel,eloquent,laravel-5,Php,Laravel,Eloquent,Laravel 5,在尝试将新获取的数据插入Laravel时,我无法在数据库中插入两个字段,即type和provider 这是我的密码: $user = User::create([ 'name' => $userData->name, 'username' => $userData->name, 'email' => $userData->email, 'password' => 'asdffdas', 'type' => '

在尝试将新获取的数据插入Laravel时,我无法在数据库中插入两个字段,即type和provider

这是我的密码:

$user = User::create([
    'name' => $userData->name,
    'username' => $userData->name,
    'email' => $userData->email,
    'password' => 'asdffdas',
    'type' => 'standard',
    'provider' => $userData->id,
    'active' => 1
  ]);
如果我回显
$userData->id
,我会设法接收一个有效的整数,但是在插入之后,类型始终是第一个
枚举
,而提供程序始终是0


知道为什么会发生这种情况吗?

您必须确保字段位于$fillable=[];模型的参数

质量分配

创建新模型时,将属性数组传递给模型构造函数。然后通过体量指定将这些属性指定给模型。这是方便的;然而,当盲目地将用户输入传递到模型中时,这可能是一个严重的安全问题。如果用户输入被盲目地传递到模型中,用户可以自由地修改模型的任何和所有属性。因此,默认情况下,所有雄辩的模型都可以防止大规模分配

To get started, set the fillable or guarded properties on your model.

Defining Fillable Attributes On A Model

The fillable property specifies which attributes should be mass-assignable. This can be set at the class or instance level.

class User extends Eloquent {

    protected $fillable = array('first_name', 'last_name', 'email');

}

您可能想回显
$user->id
,而不是
$userData->id
?提供商是否碰巧是
tinyint