3
내가 가진이 데이터베이스와 관련 업데이트 :
부모laravel - 많은 '차일'
| id | name |
+----+--------+
| 1 | Paul |
| 2 | Annet |
차일
| id | name |
+----+-----------+
| 1 | Micheal |
| 2 | Susan |
및 피벗 테이블
parents_childs
| parent_id | child_id | custom_field_1 | custom_field_2 |
+-----------+----------+----------------+----------------+
| 1 | 1 | value_1 | (null) |
| 2 | 1 | value_another | value_3 |
및 표준 관련 belongsToMany
public function parents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany('\App\Parent', 'parents_childs', 'child_id', 'parent_id')
->withPivot(
'custom_field_1',
'custom_field_2'
);
}
이제 특정 부모의 피벗 필드를 업데이트해야합니다. 예 :
SET red_value FOR custom_field_2 WHERE child_id = 1 AND parent_id = 2
어떻게하면 QueryBuilder없이이 작업을 수행 할 수 있습니까? the docs에서