1
我有一个额外列的数据透视表。在更新额外列之前,我需要检查此表中是否存在一对数据。 这里有两个问题的顺序,首先我怎么做这个检查?雄辩:检查数据透视表(主键+额外列)中的现有数据
我想是这样
If ($user->pivot_table->contains($key, '&&', $extra_column)){}
无济于事。
其次,你如何更新数据透视中的额外列?
我有一个额外列的数据透视表。在更新额外列之前,我需要检查此表中是否存在一对数据。 这里有两个问题的顺序,首先我怎么做这个检查?雄辩:检查数据透视表(主键+额外列)中的现有数据
我想是这样
If ($user->pivot_table->contains($key, '&&', $extra_column)){}
无济于事。
其次,你如何更新数据透视中的额外列?
//这是什么工作对我来说:
$user = Auth::user();
$key = $request->input('key');
$extra_column = $request->input('extra_column');
if (count($user->groups()->where('key', $key)->where('extra_column', $extra_column)->first())){
// fails (data exists already)
}else{
//update pivot
$user->groups()->updateExistingPivot($key, ['extra_column' => $extra_column]);
}