Laravel 5.3:firstOrCreate不会插入/更新值

时间:2017-01-21 06:29:40

标签: php laravel-5.3

我正在尝试使用findOrCreate方法更新或插入一行(如果项目不存在)

这是我的代码

Pickupaddress::firstOrCreate(
                [
                    'art_id'=>$artId
                ],
                [

                         'address_line1' => $request->addressLine1,
                         'address_line2' => $request->addressLine2,
                         'country'       => $request->country,
                         'postal_code'   => $request->postalCode,
                         'mobile_number' => $request->mobileNumber,
                         'region'        => $request->region,
                          'art_id'        => Auth::id()
                ]
            );

但只更新了时间戳字段,所有其他列都填充了NULL

修改

strict中将false值更新为config\database.php,但它没有被提及

1 个答案:

答案 0 :(得分:2)

您是否已在fillable模型中将字段设置为Pickupaddress

根据您的帖子,它将类似于:

    protected $fillable = [
            'address_line1',
            'address_line2',
            'country',      
            'postal_code',  
            'mobile_number',
            'region',       
            'art_id'
    ];