Eloquent “重复”;删除“u at”;基于Laravel 5.5的sql更新请求

Eloquent “重复”;删除“u at”;基于Laravel 5.5的sql更新请求,eloquent,laravel-5.5,Eloquent,Laravel 5.5,我在控制器中创建了销毁方法: public function destroy($id) { $sector = Sector::findOrFail($id); // on update lang_sector pour chaque id $sector_ids = $sector->langs()->allRelatedIds(); foreach ($sector_ids as $id){ $sector->langs()-

我在控制器中创建了销毁方法:

public function destroy($id)
{
    $sector = Sector::findOrFail($id);
    // on update lang_sector pour chaque id
    $sector_ids = $sector->langs()->allRelatedIds();
    foreach ($sector_ids as $id){
        $sector->langs()->updateExistingPivot($id, ['lang_sector.deleted_at' => Carbon::now(), 'lang_sector.updated_at' => Carbon::now()]);
    }
    $sector->valuechains()->update(
        [
            'valuechains.deleted_at' => Carbon::now(),
            'valuechains.updated_at' => Carbon::now()
        ]
    );

    Sector::where('id', $id)->delete();
}
在我的模型中:

protected $table = "sectors";
protected $fillable = ['admin_id'];
protected $dates = [
    'created_at',
    'updated_at',
    'deleted_at'
];
public function langs() {
    return $this->belongsToMany('App\Lang')
        ->withPivot(
            'sectname',
            'sectshortname',
            'sectdescription',
            'sectshortdescription'
        )
        ->withTimestamps();
}

public function valuechains()
{
    return $this->hasMany('App\Valuechain');
}
public function segments()
{
    return $this->hasManyThrough('App\Segment', 'App\Valuechain');
}
public function keyneeds()
{
    return $this->hasManyThrough('App\Keyneed', 'App\Segment', 'App\Valuechain');
}
销毁条目时,sql请求出现问题:

更新
valuechains
设置
valuechains
删除时间
='2018-05-09 16:10:32',
valuechains
更新时间='2018-05-09 16:10:32',
更新时间:
='2018-05-09 16:10:32',其中
值链
扇区id
='2'和
值链
扇区id不为空


更新的_在没有任何特殊原因的情况下出现

之所以发生这种情况,是因为您明确要求在此行中设置
updated_at
列:

'valuechains.updated_at' => Carbon::now()
在更新过程中,Laravel会自动在处设置
updated\u,因此您不需要自己显式更新它

您应该能够删除该显式行,并且
处的
updated\u仍将被更新


Laravel应该足够聪明,能够检测到重复的列更新,可惜不是这样。

如此明显。。。谢谢你的帮助!它很好用。。。我在细分市场和关键需求方面遇到了类似的问题。。。我没有找到如何更新数据透视表,如lang_valuechain、lang_segment和lang_keyneed。。。事实上,我正在尝试对几个表和透视表进行级联更新。。。